PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This seems rather a simplistic question, however, it would appear that I am still not sure how to do this
I need to take the input of a web form and put the result into variables:
for example: I want to take a webform that asks two questions, 1 zipcode and 2 radio button selection for metric or standard and have the action return what the user types into a 2 variables.
Also I would like to have this puppy have a default situation before the form is even entered.
simply pointing the action to a php script will give you all the data they entered. As for the "default situation," you can simply fill the form fields with default bits of data if you like..
/*-This will retrieve the forms zipcode textbox.-*/
$ZipCode = $_POST['zipcode'];
/*-This will retrieve the users radioselect selection (either 1 or 0)-*/
$RadioSelect = $_POST['radioselect']
Note that you should use the $_POST and $_GET global variables according to the forms method (either post or get).
<?php
if(empty($_POST['zipcode'])) {
$ZipCode = "Please enter your zip code.";
}
/*-Please note that if an option was selected that the radio buttons WILL NOT appear.
* you would need to extend the if-statement. This is only to show how to do a
* default value.-*/
if(empty($_POST['radioselect'])) {
$RadioSelect =
"<input type="radio" name="radioselect" value="1" checked="checked" />".
"<input type="radio" name="radioselect" value="0" />";
}
?>
<form method="post" action="validateform.php">
<input type="text" name="zipcode" value="<?php echo $ZipCode; ?>" />
<?php echo $RadioSelect; ?>
</form>
<?php
if(empty($_POST['zipcode'])) {
$ZipCode = "Please enter your zip code.";
}
/*-Please note that if an option was selected that the radio buttons WILL NOT appear.
* you would need to extend the if-statement. This is only to show how to do a
* default value.-*/
if(empty($_POST['radioselect'])) {
$RadioSelect =
'<input type="radio" name="radioselect" value="1" checked="checked" />
<input type="radio" name="radioselect" value="0" />';
}
?>
<form method="post" action="validateform.php">
<input type="text" name="zipcode" value="<?php echo $ZipCode; ?>" />
<?php echo $RadioSelect; ?>
</form>