• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validating forms

So as to my understanding I was supposed to put this somewhere in my viewfile where I want the errors to show up, in case of failure:
<?php echo validation_errors(); ?>
Very sadly this generates an error (undefined function), so I guess I made a mistake. Can any one point me in the right direction?

My controller:
function register(){
   //Load required lib's:
   $this->load->helper(array('form', 'url'));
   //Setting rules
   $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'required|matches[password_confirm]');
   $this->form_validation->set_rules('password_confirm', 'Confirm password', 'required');
   $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
   $this->form_validation->set_message('checkIPban', 'Your IP has previously been banned and you may not regiser again.');
   $this->form_validation->set_rules('ip', 'Banned IP', 'checkIPban');
   //check rules
   if ($this->form_validation->run() == FALSE){
    $data['formResponse'] = "Form validation failed!";
   // load fielddatas
   if($ipbwi->member->create($_POST['username'], $_POST['password'], $_POST['email'], true, $_POST['displayname'])){
    if($ipbwi->member->login($_POST['username'], $_POST['password'])){
     header('location: '.ipbwi_WEB_URL).die();
  //Show files

Not sure why that wouldn't work as validation_errors() is located in the form_helper code, which you are loading, but you can try replacing
$data['formResponse'] = "Form validation failed!";
$data['formResponse'] = validation_errors();
and in your view see if $formResponse has any data and display it if it does. It will be an empty string if there are no errors.

Yea, it could fix the problem, but how about set
<?php //echo $this->input->ip_address(); ?>
It's also in my view file, but it causes my header file not to be loaded and the input field not to be shown.

They changed some things in CI and the global CI object isn't available to views. They probably did this because in MVC the Controller should be sending any data to the view and not the view directly accessing it on its own.

Just send the IP in a variable to the view just like with form_errors() or any other dynamic data you are sending to the view.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.