1

Please please please can someone help me

$this->load->library('form_validation');
  $this->load->helper('cookie');

  $data = array();


  if($_POST) { 
   // Set validation rules including additional validation for uniqueness
   $this->form_validation->set_rules('yourname', 'Your Name', 'trim|required');
   $this->form_validation->set_rules('youremail', 'Your Email', 'trim|required|valid_email');
   $this->form_validation->set_rules('friendname', 'Friends Name', 'trim|required');
   $this->form_validation->set_rules('friendemail', 'Friends Email', 'trim|required|valid_email');

   // Run the validation and take action
   if($this->form_validation->run()) { 
    echo 'valid;
   }
  }
  else{
   echo 'problem';
  }

Form validation is coming back with no errors can cany one see why?

2 Answers 2

1

Is it actually echoing 'valid'? (you're missing an apostrophe there, btw)

The code you show will only echo 'problem' when $_POST is false, not when validation fails. Without knowing more, it may be as simple as:

// Run the validation and take action
if($this->form_validation->run()) { 
 echo('valid');
} else {
 echo('invalid');
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try like this without checking if $_POST is set - not really needed:

//validation rules here
//
if ($this->form_validation->run() == TRUE) {
     //do whatever that shall be run on succeed
} else {
     $this->load->view('form'); //load the form
}

Read more about the controller part here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.