Hello everybody,
This is my first post on this forum and I wish to share with you my problem, hoping that someone has gone through the same problem as I have.
My form looks like this:
Form html code:
Form process:
And the rules.php looks like this:
The validation message returns the "title" of the fullname and message fields (Full Name, Your Message) but for the how radio group returns "how" instead of "How to".
Any help will be very appreciated.
This is my first post on this forum and I wish to share with you my problem, hoping that someone has gone through the same problem as I have.
My form looks like this:
Form html code:
Code:
<form method="post" action="process.php"> <input type="text" name="fullname"/> <textarea name="message"></textarea> <input type="radio" name="how" value="1" /> <input type="radio" name="how" value="2" /> <input type="radio" name="how" value="3" /> <input type="submit" value="Send"> </form>
Code:
<?php require 'rules.php'; function get_errors($form_data,$rules){ // returns an array of errors $errors=array(); foreach($form_data as $name=>$value){ if(!isset($rules[$name]))continue; $rule=$rules[$name]; $hname=htmlspecialchars($rule['title']); if(isset($rule['required']) && $rule['required'] && !$value) $errors[]='Field <strong>'.$hname.'</strong> is required.'; $rules[$name]['found']=true; } foreach($rules as $name=>$values){ if(!isset($values['found']) && isset($values['required']) && $values['required']) $errors[]='Field '.htmlspecialchars($name).' is required.'; } return $errors; } $errors=get_errors($_POST,$form_rules,$message); if(!count($errors)){ echo 'Message sent'; } else{ echo $errors; } ?>
Code:
<?php $form_rules=array( 'fullname'=>array( 'required'=>true, 'title'=>'Full Name', ), 'message'=>array( 'required'=>true, 'title'=>'Your Message', ), 'how'=> array ( 'required'=> true, 'title'=>'How to', ) ); ?>
Any help will be very appreciated.
Comment