Home > Archive > PHP Language > May 2006 > Simple variable passing?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simple variable passing?
|
|
|
| There have been a ton of threads on passing variables but my problem
is much more simplistic. I have tried to figure it all out but I am
just not that good at this. So here goes:
I have a button on a web page that links to an HTML form. I want to
use a single variable like John_Doe_123456 and pass it to the HTML
form so it can be put in a hidden field. When the form is sumbitted,
the value will go with it. That's it.
I get the url part of
http://www.somepage.com/formpage.ht...e=JohnDoe123456 (I hope
this is right)
I have this as the button's link.
It opens up an HTML form with a number of fields. One is a hidden
field with a "value =" parameter.
I just do not know how to take that value and place it into the hidden
field.
This must be a simple one or two line affair but I just cannot make it
work. I really would appreciate some help. I can save the .htm form as
..php if it makes it easier.
One more thing. If the form is opened as a new window with Javascript
instead of a straightfoward link to a new page would it make a
difference.
Thanks
| |
| Geoff Berrow 2006-05-13, 3:57 am |
| Message-ID: <pi4c62p8jankg8ssto4p6vro4p4m53roug@4ax.com> from Ellie
contained the following:
>http://www.somepage.com/formpage.ht...e=JohnDoe123456 (I hope
>this is right)
>
>I have this as the button's link.
>
>It opens up an HTML form with a number of fields. One is a hidden
>field with a "value =" parameter.
>
>I just do not know how to take that value and place it into the hidden
>field. This must be a simple one or two line affair but I just cannot make it
>work. I really would appreciate some help. I can save the .htm form as
>.php if it makes it easier.
It would, provided you have php enabled on your server.
Then it's just
<input type='hidden' name='whatever' value='<?php echo
$_GET['username']; ?>'>
But there may be more to it, depending on what you want to do with this
hidden field.
>
>
>One more thing. If the form is opened as a new window with Javascript
>instead of a straightfoward link to a new page would it make a
>difference.
Yes, loads of people now have popups blocked due to abuse. Also, this
would happen without a server call and so you'd have to write it in
JavaScript
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
| I should not be surprised that it worked, but it most certainly did.
OK, now let me get crazy. I know I can have up to two variables passed
in the url separated by the '&' If I wanted a second variable, how
would I grab that one.
Bye the way, I have been working on this for days to make it work.
Thank you very much.
On Sat, 13 May 2006 08:29:11 +0100, Geoff Berrow
<blthecat@ckdog.co.uk> wrote:
>Message-ID: <pi4c62p8jankg8ssto4p6vro4p4m53roug@4ax.com> from Ellie
>contained the following:
>
>
>It would, provided you have php enabled on your server.
>
>Then it's just
>
><input type='hidden' name='whatever' value='<?php echo
>$_GET['username']; ?>'>
>
>But there may be more to it, depending on what you want to do with this
>hidden field.
>
>
>Yes, loads of people now have popups blocked due to abuse. Also, this
>would happen without a server call and so you'd have to write it in
>JavaScript
| |
| Geoff Berrow 2006-05-13, 6:57 pm |
| Message-ID: <qoad62tmae29hrmhv51fslhdoo97um521p@4ax.com> from Ellie
contained the following:
>OK, now let me get crazy. I know I can have up to two variables passed
>in the url separated by the '&' If I wanted a second variable, how
>would I grab that one.
You can have more that two, but there is a character limit with GET
If you have www.example.com?var1=ab&var2=cde&var3=fghi
Then the values are contained in
$_GET['var1']
$_GET['var2']
$_GET['var3']
By the way, if you are putting the URL in html be sure to use &
instead of a plain & so your pages will validate.
>Bye the way, I have been working on this for days to make it work.
>Thank you very much.
No problem.
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
|
I used the value with just a "&" and called a form with a .php ending
and it worked fine. Is this what you mean?
On Sat, 13 May 2006 19:23:00 +0100, Geoff Berrow
<blthecat@ckdog.co.uk> wrote:
>Message-ID: <qoad62tmae29hrmhv51fslhdoo97um521p@4ax.com> from Ellie
>contained the following:
>
>
>You can have more that two, but there is a character limit with GET
>
>If you have www.example.com?var1=ab&var2=cde&var3=fghi
>
>Then the values are contained in
>
>$_GET['var1']
>$_GET['var2']
>$_GET['var3']
>
>By the way, if you are putting the URL in html be sure to use &
>instead of a plain & so your pages will validate.
>
>
>No problem.
| |
| Geoff Berrow 2006-05-13, 6:57 pm |
| Message-ID: <kfsd6256pdnek4golqui0otspumisgqnk0@4ax.com> from Ellie
contained the following:
>I used the value with just a "&" and called a form with a .php ending
>and it worked fine. Is this what you mean?
I mean that if you are putting the link in your web page you should
write it like this:
<a href="mylinkpage.php?var1=ab&var2=cde&var3=fghi">Link to
mylinkpage</a>
The & will work, but if you validate your pages (as you should) the
validator will barf.
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
|
I hope I am not taking advantage by asking another question.
Everything you told me worked great so far. I am using a common
program called form-2-mail.php to process the forms.
The forms now can read an identifier so it sends back the form with
this info. I would also like to send a copy of all the information to
the person who filled in the form.
They use an array in the processing program that looks like this:
$emailaddresses = Array (
'1' => 'person1@mail.com',
'2' => 'person2@aol.com',
'3' => '',
It allows for up to 20 individuals to receive the form data. So, I
realized that if I put in a statement
$emailaddresses[3] = "anotherperson@mail.com"; It would send the data
to them as well.
Now I want to grab one of the form fields that identifies who it is
from (the hidden field that you helped me to populate) and use it as a
case statement switch. That way, depending on who filled out the form,
I can send them the data as well. I tried this:
switch ($_POST["id_field"])
{
case "some_person_1":
$emailaddresses[3] = "someperson1@mail.com";
break;
case "some_person_2":
$emailaddresses[3] = "someperson2@mail.com";
break;
}
id_field is the name of the hidden field that I populated in the form
It could not populate the third space in the array as it would when I
used the statement outside of the case statement.
Could you tell me what I am doing wrong?
Thank you
On Sat, 13 May 2006 22:48:32 +0100, Geoff Berrow
<blthecat@ckdog.co.uk> wrote:
>Message-ID: <kfsd6256pdnek4golqui0otspumisgqnk0@4ax.com> from Ellie
>contained the following:
>
>
>I mean that if you are putting the link in your web page you should
>write it like this:
>
><a href="mylinkpage.php?var1=ab&var2=cde&var3=fghi">Link to
>mylinkpage</a>
>
>The & will work, but if you validate your pages (as you should) the
>validator will barf.
| |
| Geoff Berrow 2006-05-15, 3:59 am |
| Message-ID: <13rf629oou28p9ouacs14f68p5ebsslg87@4ax.com> from Ellie
contained the following:
>
>It could not populate the third space in the array as it would when I
>used the statement outside of the case statement.
>
>Could you tell me what I am doing wrong?
There is nothing wrong with the code you posted.
Try echoing $_POST["id_field"] to the screen before the switch
statement to make sure it contains what you think it does.
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
|
If I look for a field in the form that was manually typed in by the
user, I can see it if I echo the $_POST. However, if I try to echo the
hidden or text field that I populated with the $GET routing you gave
me, it doesn't even stop to echo anything. It just returns the success
page as if the statement was not there.
What I do not get is, the form returns both fields and they should
both be in the $_POST array.
On Mon, 15 May 2006 07:33:10 +0100, Geoff Berrow
<blthecat@ckdog.co.uk> wrote:
>Message-ID: <13rf629oou28p9ouacs14f68p5ebsslg87@4ax.com> from Ellie
>contained the following:
>
>
>There is nothing wrong with the code you posted.
>
>Try echoing $_POST["id_field"] to the screen before the switch
>statement to make sure it contains what you think it does.
| |
| Geoff Berrow 2006-05-15, 6:57 pm |
| Message-ID: <d53h629dj8gvkk5a6d1p2k8637kl3g7g9j@4ax.com> from Ellie
contained the following:
>If I look for a field in the form that was manually typed in by the
>user, I can see it if I echo the $_POST. However, if I try to echo the
>hidden or text field that I populated with the $GET routing you gave
>me, it doesn't even stop to echo anything. It just returns the success
>page as if the statement was not there.
>
>What I do not get is, the form returns both fields and they should
>both be in the $_POST array.
Yes, they should be.
Try putting this in somewhere:-
print "<pre>";
print_r($_POST);
print "</pre>";
This will echo all your $_POST variables to the screen so you can see
what you are getting. Are you sure the hidden field is being populated?
If that doesn't give you any clues, you'll have to post your code.
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
| $_GET['form_variable_name']; will get anything that is part of an url
using GET. A form can declare its method as GET, in which case the
attribute value pairs are sent with the url and are visible in the
browser location bar, or, more usually, a form uses the POST method in
which case your script must use $_POST['form_variable_name'] to
retrieve things.
You can use $_REQUEST['form_variable_name'] and that will get both GET
and POST variables. Its more flexible if the you're likely to use
both but less secure if you're sure you'll only use POST in your forms
and want to prevent anyone from 'faking' your form in a url.
Rob
On Mon, 15 May 2006 10:17:39 -0400, Ellie <luvtadance@aol.com> wrote:
[color=darkred]
>
>If I look for a field in the form that was manually typed in by the
>user, I can see it if I echo the $_POST. However, if I try to echo the
>hidden or text field that I populated with the $GET routing you gave
>me, it doesn't even stop to echo anything. It just returns the success
>page as if the statement was not there.
>
>What I do not get is, the form returns both fields and they should
>both be in the $_POST array.
>
>
>On Mon, 15 May 2006 07:33:10 +0100, Geoff Berrow
><blthecat@ckdog.co.uk> wrote:
>
|
|
|
|
|