+ Reply to Thread
Results 1 to 1 of 1

Thread: Regex radio button validation not working...

  1. #1
    jbdesign's Avatar
    jbdesign is offline x10Hosting Member jbdesign is an unknown quantity at this point
    Join Date
    Mar 2009
    Location
    Nampa, ID, USA
    Posts
    26

    Regex radio button validation not working...

    EDIT:I just figured out what my problem was... god I feel so stupid sometimes. Please feel free to delete this thread.

    On the form I am making I am trying to require the visitor to select a yes or no radio button, before the information is submitted. Problem is the regex validation isn't working, they can submit without selecting either one. Here is the code:

    Code:
    <?php
    if(isset($_POST['submitted']) and $_POST['submitted'] == "yes") 
    { 
      foreach($_POST as $field => $value)         
      { 
        if(empty($value)) 
        { 
          if($field != "middle_name") 
          { 
             $blank_array[] = $field; 
          } 
        } 
        else                                                 
        { 
          $good_data[$field] = strip_tags(trim($value)); 
        } 
      } 
      if(@sizeof($blank_array) > 0) 
      { 
      /*Display error message if information is not entered*/ 
        $message = "<p style='color: red; margin-bottom: 0; 
                     font-weight: bold'> 
                     You didn't fill in one or more required fields. 
                     You must enter: 
                     <ul style='color: red; margin-top: 0; 
                     list-style: none' >";
        foreach($blank_array as $value) 
        { 
           $message .= "<li>$value</li>"; 
        } 
        $message .= "</ul>"; 
        echo $message; 
        extract($good_data); 
        include("lesson4_form.inc"); 
        exit();    
      } 
      foreach($_POST as $field => $value) 
    { 
      if(!empty($value)) 
      { 
        $name_patt = "/^[A-Za-z' -]{1,50}$/";
        $radio_patt = "/(yes|no)/i"; 
        if(preg_match("/name/i",$field)) 
        { 
          if(!preg_match($name_patt,$value)) 
          { 
            $error_array[] = "$value is not a valid name"; 
          } //end of name check
        }
        if(preg_match("/status/i",$field)) 
        { 
          if(!preg_match($radio_patt,$value)) 
          { 
            $error_array[] = "$value is not a valid status"; 
          } //end of radio button check
        } 
      } 
      $clean_data[$field] = strip_tags(trim($value)); 
    } 
    if(@sizeof($error_array) > 0) 
    { 
      $message = "<ul style='color: red; list-style: none' >"; 
      foreach($error_array as $value) 
      { 
        $message .= "<li>$value</li>"; 
      } 
      $message .= "</ul>"; 
      echo $message; 
      extract($clean_data); 
      include("information_form.inc"); 
      exit(); 
    } 
    else 
    { 
      echo "Data is all okay"; 
    }; 
    } 
    else 
    { 
      include("information_form.inc"); 
    } 
    ?>
    I stripped out some of the other code that doesn't pertain to my problem.
    Last edited by jbdesign; 05-28-2009 at 01:23 PM.

+ Reply to Thread

Similar Threads

  1. TCPDF radio button
    By javilla in forum Programming Help
    Replies: 1
    Last Post: 05-10-2009, 07:10 AM
  2. Flash button for 50 Credits:
    By satheesh in forum The Marketplace
    Replies: 4
    Last Post: 01-25-2008, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers