identifying form controls from php script
Moderator: General Moderators
identifying form controls from php script
If I do not know the names of textfields on a form, how can I identify the names from within a PHP script specified in the 'action' property of the form.
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Give a name to all of your forms in the forms page, then in the php script that processes it will have all of the variables in $_REQUEST['name']. More specifically, if you used the "post" method to send the form, they will be in $_POST['name'] , and for the "get" method $_GET['name'] .
Example:
forms.html:
process.php:
But I guess if you for some reason are unable to give the text fields names you could get the names of the fields by doing:
Note: if the fields are not named, they are not passed to $_POST
Tell me if you need any elaboration.
Example:
forms.html:
Code: Select all
<form action="process.php" method="post">
<input type="text" name="mytext"><br>
<input type="submit" name="submit" value="Submit the text">
</form>Code: Select all
<?php
echo "Your text is: " . $_POSTї'mytext'];
?>Code: Select all
foreach( $_POST as $key => $val )
echo "Name of field: " . $key . "<br>\n";Tell me if you need any elaboration.
You may. If your php.version is less than 4.2 or register_global has been explicitly turned on
http://www.devnetwork.net/forums/viewtopic.php?t=511
http://www.devnetwork.net/forums/viewtopic.php?t=511