The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP3 and the HTML Form
Discuss PHP3 and the HTML Form in the PHP Development forum on Dev Shed. PHP3 and the HTML Form PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 2nd, 1999, 02:32 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Is there an array in PHP that keeps all the variables that the user entered in the form, like $name, $email, etc?
The purpose is: send an email to the webmaster saying:
$name: John Richard
$email: john@richard.com
So, if I chance the name of the variables, or if I add another variable in the form.. it works..
Thanks
Luís
|

December 8th, 1999, 09:24 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
I don't know what your problem is, but form data allready gets passed to the result page in subsequent variables.
So if you build a form like this
<form method="POST" action="result.php" name="mailform">
Name:<input type="text" size="30" name="frm_name"><br>
Email:<input type="text" size="30" name="frm_email"><br>
<input type="submit">
</form>
And you would submit this form with John Richard as Name and john@richard.com as email, the variables $frm_name and $frm_email contain the data entered in the form, in this case:
$frm_name="John Richard" $frm_email="john@richard.com"
[This message has been edited by Hans (edited 12-08-99).]
|

December 8th, 1999, 10:15 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
I need an array that keeps all the names and values of the form.
So, I don't need to know all the variable names to send the e-mail, because I'll have all the form field values in this array..
In perl, I would get the string "?name=value&name2=value", split and put it in an array..
How can I do it in PHP??
Thanks
luis
|

December 8th, 1999, 10:26 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Check the manual for $PHP_POST_VARS
|

December 8th, 1999, 09:47 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Actually, it's $HTTP_POST_VARS if your form uses the POST method, $HTTP_GET_VARS for the GET method.
--
Alan Little
Holotech Web Design
http://www.holotech.net/
[This message has been edited by Darguz (edited 12-08-99).]
|

December 9th, 1999, 09:51 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Thanks, Alan. Can blame my memory on all the cough medicine URL
Hey, I knew what I /meant/ to write....
|

December 9th, 1999, 12:46 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
So..
I put the command
<? print "$HTTP_POST_VARS - $HTTP_GET_VARS"; ?>
and it prints
Array - Array
So.. I think these stuff is not available in my ISP... or am I doing something wrong?
|

December 9th, 1999, 01:09 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
No, that's what you should get :0
$HTTP_POST_VARS (and GET) are arrays. They contain in data passed by POST and GET methods respectively, with the name/value pairs as the index and data respectively.
For example, if you pass the query string ?this=that&those=these
then $HTTP_GET_VARS[this] would contain the value "that" and $HTTP_GET_VARS[those] would contain the value "these"
Alternately, if you use a form you would use $HTTP_POST_VARS instead. In your application, all you would need to do is to use EACH across the $HTTP_POST_VARS array to get the keys (since you say you want to be able to change the form.)
HTH
Rod
|

December 9th, 1999, 07:11 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
$HTTP_POST_VARS and $HTTP_GET_VARS are associative arrays (see the documentation for a description), containing the field names and values passed from your form. Use the each() construct to walk through them:
while(list($var, $val) = each($HTTP_POST_VARS)) {
[do stuff]
}
On each iteration of the loop, $var and $val will have the name and value, respectively, of a field in your form.
------------------
Alan Little
Holotech Web Design
www.holotech.net/
[This message has been edited by Darguz (edited 12-09-99).]
[This message has been edited by Darguz (edited 12-09-99).]
|

December 10th, 1999, 08:55 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Isn't that what I said URL
|

December 15th, 1999, 07:06 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
But what if you get another array inside the form from, for example, multiple checkboxes/selects within a group?
That gets a bit more complicated when only using HTTP_POST_VARS.
Why not just catch all the variables (by name) on a reload (after submit) of the page on which you then also perform a mail() function and clear up the form again.
I have good experience with that. Anyone any other ideas?
Regards, Peter
|

December 15th, 1999, 08:03 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
PAV,
You make good points. In fact, that is exactly what I do.
However, go back and read the original question. He wants to be able to add a field to the form without modifying the action script. To do that you have to have your form in an array, either one he creates or $HTTP_POST_VARS.
I don't mean this as a flame, but I've read many posts from you recently, and you give good advice except that your responses seem to not take into account special needs as defined by the person posting the question.
The way you have solved a problem is not always the BEST way for everyone.
|

December 15th, 1999, 09:58 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
I'm sorry if that's the impression I made, it was surely not my intention to do so...
But isn't this still a discussion forum? URL
|

December 15th, 1999, 10:49 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Thanks guys!
Now.. that worked.. you're the best. Now, I don't know if I dedicate myself to ASP or to PHP.
But.. it's subject for another discussion..
Thanks
Luís
|

December 15th, 1999, 12:10 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Maybe this won't work with what you want to do, but you could NAME all your input fields something like FIELD[], which will store all the form fields into the array FIELD, and can be accessed with a for loop like:
for($x=0;$x<$count($FIELD);$x++)
{
do stuff for each $FIELD[$x]
}
You wouldn't know what each value was for though, is the only problem.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|