set_radio + Validation Problems - El Forum - 10-26-2012
[eluser]Unknown[/eluser]
I am having a problem using set_radio with form validation. As our code works now, it sees if the radio buttons are clicked, not re-selected, and then is able to validate. The code for the buttons is seen here:
Code: </tr>
<tr>
<div value="radioButtons">
<td>Do You Have a PayPal Account <span class="error">*</span> : </td>
<td>
<input name="mail_account" type="radio" id="p_same" value="same" <?php echo set_radio('mail_account', 'same'); ?> /> Yes(same as email address as above.)<br/>
<input name="mail_account" type="radio" id="p_diff" value="diff" <?php echo set_radio('mail_account', 'diff'); ?>/> Yes(different than above.)<br/>
<input name="mail_account" type="radio" id="p_checkInMail" value="checkInMail" <?php echo set_radio('mail_account', 'checkInMail'); ?> /> No(I would prefer to receive a check in the mail.)
</div>
<!-- used for validation -->
<input type="hidden" id="temp_mid" value="" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<!-- the tr with id bx is hidden by on load -->
<tr id="bx">
<td>Paypal Email <span class="error">*</span> : </td>
<td valign="top"> <input type="text" value="<?php
if ($data['paypal_emailid'] != "") {
echo $data['paypal_emailid'];
}
?>" name="paypal_emailid" id="paypal_emailid" maxlength="255">
<?php echo form_error('paypal_emailid'); ?></td>
</tr>
Here is the validation that has been done:
Code: function validate_playpal()
{
//$('#temp_mid').val('clicked');
var temp=$('#temp_mid').val();
//alert(temp);
//THE CODE BELOW USED TO BE if(temp=='') I have tried both ways, dont work
if(document.getElementById('p_diff').checked== false && document.getElementById('p_same').checked== false && document.getElementById('p_checkInMail').checked== false)
{
alert('Please select the PayPal account option.');
$('radioButtons').focus();
return false;
}
if(document.getElementById('p_diff').checked== true && document.getElementById('paypal_emailid').value=='')
{
alert('Please provide your PayPal email address.');
document.getElementById('paypal_emailid').focus();
return false;
}
if(document.getElementById('paypal_emailid').value!='')
{
if(!email_format(document.getElementById('paypal_emailid').value)){
alert('Please enter valid email address.');
document.getElementById('paypal_emailid').value="";
document.getElementById('paypal_emailid').focus();
return false;
}
}
return true;
}
Every time the server side sends a validation error, the form repopulates correctly, but the alert saying that I have to select a Paypal account comes up again, even though the correct radio button is selected. What am I doing wrong? Is this just a bug? Thanks.
|