hello,
I found a tutorial script that works for me but it doesn't seem to work well with radio buttons. I'm hoping someone could have a look at that script and help me get it working with the radiobutton.
the selection carrie over to the process.php script but cant seem to process the selection.
need 2 things:
1 process the selection.
2. in the event user enters incorrect information somewhere else i like to be able to go back to the form with the users original radio button selection. eg. Name: <input type="text" name="name" value="<?php echo $name; ?>" > <br />
any help you can give me would be greatly appreciated.
index.php
PHP Code:<body>
<h3>Form testing</h3>
<?php echo $errorString; ?>
<br />
<form name="formprocess" method="POST" action="process.php">
Name: <input type="text" name="name" value="<?php echo $name; ?>" > <br />
eMail: <input type="text" name="email" value="<?php echo $email; ?>" > <br />
Birthday:<input type="text" name="birthday" value="<?php echo $birthday; ?>" /><br />
<br />
<p> <input type="radio" name="radiobutton" value="1"> OptionOne </p>
<p> <input type="radio" name="radiobutton" value="2"> OptionTwo </p>
<p> <input type="radio" name="radiobutton" value="3"> OptionThree</p>
<input type="submit" name="formSubmit" value="Submit">
</form>
</body>
process.php - form processing script
PHP Code:<?php
$allowedFields = array(
'name',
'email',
'birthday',
'radiobutton',
);
$requiredFields = array(
'name',
'email',
'radiobutton',
);
echo $_POST['radiobutton'];
echo '<br />';
print_r($_POST);
//loop through the POST array
$fieldErrors = array();
foreach($_POST as $key=>$value)
{ // allowed fields
if(in_array($key, $allowedFields))
{ $$key = $value;
// required field?
if(in_array($key, $requiredFields) && $value == '')
{ $fieldErrors[] = "The field $key is required.";
}
}
}
// Any errors
if(count($fieldErrors) > 0)
{ $errorString = '<p>There was an error processing the form.</p>';
$errorString . 'ul>';
foreach($fieldErrors as $errorVal)
{ $errorString .= "<li>$errorVal</li>"; }
$errorString .= '</ul>';
include 'form.php';
}
else
{ echo "<br /> append to database, goes here"; }
?>



Reply With Quote

Bookmarks