close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

retain radio button value on validation fail

Thread began 4/17/2010 7:48 pm by gruant2000381341 | Last modified 4/19/2010 11:04 am by Jason Byrnes | 1301 views | 1 replies |

gruant2000381341

retain radio button value on validation fail

okay I'm stuck on something. I built a form with textfields and radio buttons. I have it set up that if a user submits the form, and it fails validation ( they left a field blank ) the form retains the info they entered into the text areas. I want the same thing to happen with the radio buttons but I can't figure out how to make that happen. I don't want a default radio button to be initially displayed...just the one that they chose before they submitted (assuming that validation failed)

<?php
// just initializing my variables here
$msg_to_user = "";
$edate = "";
$time = "";
$desc = "";
$locat = "";
$outpt = "";
$region = "";
?>

<?php
// here is where i am doing my validation checks
if ($_POST['edate'] != "") {

$edate = $_POST['edate'];
$time = $_POST['time'];
$desc = $_POST['desc'];
$locat = $_POST['locat'];
$outpt = $_POST['outpt'];
$region = $_POST['region'];

if (!$time) {
$msg_to_user= '<font color="FF0000">Please enter an event time.</font>';
} else if (!$desc) {
$msg_to_user= '<font color="FF0000">Please enter an event description.</font>';
} else if (!$locat) {
$msg_to_user= '<font color="FF0000">Please enter an event location.</font>';
} else if (!$outpt) {
$msg_to_user= '<font color="FF0000">Please enter output message for email.</font>';
} else if (!$region){
$msg_to_user= '<font color="FF0000">Please choose a region.</font>';
} else {
$msg_to_user= '<font color="FF0000">all done.</font>';
}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

date:<br />
<input type="text" name="edate" value="<?php echo $edate; ?>"/><br />
time:<br />
<input type="text" name="time" value="<?php echo $time; ?>"/><br />
description:<br />
<input type="text" name="desc" value="<?php echo $desc; ?>"/><br />
location:<br />
<input type="text" name="locat" value="<?php echo $locat; ?>"/><br />
output to form:<br />
<input type="text" name="outpt"value="<?php echo $outpt; ?>" /><br />
<br />

// these are the radios i want to retain the values if validation fails--------------------------------------------------------------

region:<br />
<label><input type="radio" name="region" value="regionA" />A</label><br />
<label><input type="radio" name="region" value="regionB" />B</label><br />
<label><input type="radio" name="region" value="regionC" />C</label>
<br />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php echo $msg_to_user; ?>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

In the property inspector for the radio button, click the dynamic button.

In the select value equal to field enter:
<?php echo $region; ?>

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...