If validation fail retain information for radiobutton
Dear WebAssist,
I am having trouble retaining the information on a radio checkbox.
Here is the checkbox code:
<label>
<input type="radio" name="HelpersYes" value="1" id="HelpersYes_0" />
Yes</label>
<label>
<input type="radio" name="HelpersYes" value="0" id="HelpersYes_1" />
No</label>
Very simple submitting a "1" or a "0".
If I bind the form toolkit session "HelpersYes" to the radio button and then I select as my default the DB item I get this:
<label>
<input <?php if (!(strcmp($row_SavedReportRs['HelperYes'],"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="1" id="HelpersYes_0" />
Yes</label>
<label>
<input <?php if (!(strcmp($row_SavedReportRs['HelperYes'],"0"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="0" id="HelpersYes_1" />
No</label>
Which is only using the DB record to select the default. but not the validation session.
If I just bind the form toolkit session "HelpersYes" without selecting anything as the default I do get the session creating the default. see below.
<label>
<input <?php if (!(strcmp((isset($_SESSION["WAVT_dailycurrent_507_Errors"])?ValidatedField("dailycurrent_507","HelpersYes"):""),"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="1" id="HelpersYes_0" />
Yes</label>
<label>
<input <?php if (!(strcmp((isset($_SESSION["WAVT_dailycurrent_507_Errors"])?ValidatedField("dailycurrent_507","HelpersYes"):""),"0"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="0" id="HelpersYes_1" />
No</label>
This also works fine but I need to include the default from the DB if the session "HelpersYes" is not there.
I have tried combining the two but without success. see below:
<input <?php if (!(strcmp((isset($_SESSION["WAVT_dailycurrent_507_Errors"])?ValidatedField("dailycurrent_507","HelpersYes"):""),"1"))) {echo "checked=\"checked\"";} elseif (!(strcmp($row_SavedReportRs['HelperYes'],"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="1" id="HelpersYes_0" />
Yes</label>
<label>
<input <?php if (!(strcmp((isset($_SESSION["WAVT_dailycurrent_507_Errors"])?ValidatedField("dailycurrent_507","HelpersYes"):""),"0"))) {echo "checked=\"checked\"";} elseif (!(strcmp($row_SavedReportRs['HelperYes'],"0"))) {echo "checked=\"checked\"";} ?> type="radio" name="HelpersYes" value="0" id="HelpersYes_1" />
No</label>
Is this a bug? How can I write the code so that on the radio button it will use the session as the default if there is a session, if not it will use the value from the DB.
I have checked to make sure the DB values are correct so it is something missing in the code and I do not know enough to fix it. Please can you help.
Many thanks as always