I can't seem to figure out a way to keep the checkbox value when an error occurs on the form.
The value is there but the checkbox doesnt remain selected when the errors come up , if there are any.
i have my form set up in a block:
$form = " <html code here>....";
so when my error checking goes thru it echo's $form and the error messages on the missing or invalid fields. How do i keep the selected checkbox selected...if that made any sense.
Keeping checkbox values on error...
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you need to add something that will add "selected" to the fields output so it'll look like this:
Code: Select all
<input type="checkbox" name="foo" value="bar" selected="selected" />I am a selected checkbox<br />
<input type="checkbox" name="foo" value="bif" />I am an unselected checkbox<br />yea i figured that just dunno how to put it in there using the "block"
was gonna put this after the value of the box
was gonna put this after the value of the box
Code: Select all
<?php
<? if ($gender == male) { echo " selected"; } ?>
if i put that in tho i just get a parse error....sayin something bout T_STRING T_VARIABLE something like that..
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I use something similar to this:
Code: Select all
<?php
function constructInput($type,$name,$value,$error = false,$selected = false)
{
if(in_array($type,array('checkbox','radio')))
return '<input type="' . $type . '" name="' . $name . '" value="' . $value . '" ' . ((bool)$selected ? 'selected="selected" ' : '') . '/>' . (is_string($error) ? $error : '');
else
return '<input type="' . $type . '" name="' . $name . '" value="' . $value . '" />' . (is_string($error) ? $error : '');
}
?>still probs
tried this
still not working right figured that would do it but nope...
ideas?
Code: Select all
if ($_POSTї$gender] = "male") {
$app_block2 = "
<input name="gender" type="radio" value="male" selected>
Male
<input name="gender" type="radio" value="female">
Female";
}
else if ($_POSTї$gender] = "female") {
$app_block2 = "
<input name="gender" type="radio" value="male" >
Male
<input name="gender" type="radio" value="female" selected>
Female";
}
else
$app_block2 = "
<input name="gender" type="radio" value="male">
Male
<input name="gender" type="radio" value="female">
Female";still not working
still not working...
now when it loads it automatically checks the male value
now when it loads it automatically checks the male value