CodeIgniter Forums
set_radio + Validation Problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: set_radio + Validation Problems (/showthread.php?tid=55444)



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>                        
                        &lt;input name="mail_account" type="radio" id="p_same" value="same" &lt;?php echo set_radio('mail_account', 'same'); ?&gt; /&gt; Yes(same as email address as above.)<br/>
                        &lt;input name="mail_account" type="radio" id="p_diff" value="diff" &lt;?php echo set_radio('mail_account', 'diff'); ?&gt;/&gt; Yes(different than above.)<br/>
                        &lt;input name="mail_account" type="radio" id="p_checkInMail" value="checkInMail" &lt;?php echo set_radio('mail_account', 'checkInMail'); ?&gt; /&gt; No(I would prefer to receive a check in the mail.)                  
                    </div>
                    &lt;!-- used for validation --&gt;
                    &lt;input type="hidden" id="temp_mid" value="" /&gt;
                    
                    </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    &lt;!-- the tr with id bx is hidden by on load --&gt;
                    <tr id="bx">
                     <td>Paypal Email <span class="error">*</span> : </td>
                        <td valign="top"> &lt;input type="text" value="&lt;?php
                                       if ($data['paypal_emailid'] != "") {
                                           echo $data['paypal_emailid'];
                                       }
                    ?&gt;"  name="paypal_emailid" id="paypal_emailid" maxlength="255"&gt;    
                                &lt;?php echo form_error('paypal_emailid'); ?&gt;</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.