|
Posted by J.O. Aho on 03/18/07 12:52
rsvore wrote:
> I've only been working with PHP for five months during this time I'm trying
> to improve a script written by someone by adding validation to the form. The
> form contains seven step functions with it's on validation for each page. My
> problem comes when the page is validated and the user has put a check in the
> radio button or a drop down list I can't get the script to apply that check
> back into the form when the user has to correct something else. Below is
> step3 with calls the function in this case I'm trying to get AplyMonths to
> remember that either yes or no was checked but again once the form is
> validated with an error the check comes out and the user has to select it
> again. Any help how to make this work please let me know.
First of all, youw code is a bit difficult to read IMHO, it's easier if you
use a few more newlines.
<input type=\"radio\" name=\"AplyMonths\" id=\"AplyMonths\" value=\"Y\">Yes";
if (AplyMonths == "N")
echo "checked";$this->mainContent .= "
<input type=\"radio\" name=\"AplyMonths\" value=\"N\">No"; if (AplyMonths
== "N")
echo "checked";
"checked" works only if you put it inside the input tag. And I'm not usre if
you have defined the value for "AplyMonths" correctly, maybe better you use a
variable instead.
$AplyMonths=$_REQUEST['AplyMonths'];
$this->mainContent .= "<input type=\"radio\" name=\"AplyMonths\"
id=\"AplyMonths\" value=\"Y\"";
if($AplyMonths == "Y") { $this->mainContent .= " checked"; }
$this->mainContent .=">Yes\n<input type=\"radio\" name=\"AplyMonths\"
value=\"N\"";
if($AplyMonths == "N") { $this->mainContent .= " checked"; }
$this->mainContent .= ">No\n";
In the same manner you need to test each option in your drop down menu for a
match with the old value
$this->mainContent .= "<option value=\"something\"";
if($SelectName=="something") { $this->mainContent .= " selected"; }
$this->mainContent .= ">SomeThing</option>\n";
Adding a new line after each thing you done, will make the HTML source a lot
more readable and easier for you to track problems. You may also want to take
a look at CSS and how to place html-elements instead of using the table you
are, good place for help is alt.html
--
//Aho
Navigation:
[Reply to this message]
|