CodeIgniter Forums
Form Validation Run returning true every time - 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: Form Validation Run returning true every time (/showthread.php?tid=61156)



Form Validation Run returning true every time - El Forum - 10-02-2014

[eluser]Apidcloud[/eluser]
Good evening,

I've been trying to create a simple form, but the validation isn't working as expected.
Here's the form code:
Code:
<?php
$this->load->helper('form');
echo validation_errors();
echo form_open('welcome/send_email');

$data = array(
"name" => "name",
"id" => "name",
"value" => "Nome",
"class" => "span3",
"onFocus" => "if (this.value == 'Nome') this.value = '';",
"onBlur" => "if (this.value == '') this.value = 'Nome';"
);

echo form_input($data);

$data = array(
"name" => "email",
"id" => "email",
"value" => "Email",
"class" => "span3",
"onFocus" => "if (this.value == 'Email') this.value = '';",
"onBlur" => "if (this.value == '') this.value = 'Email';"
);
  echo form_input($data);
  
   $data = array(
"name" => "message",
"id" => "message",
"value" => "Mensagem",
"class" => "span3 foot_message",
"onFocus" => "if (this.value == 'Mensagem') this.value = '';",
"onBlur" => "if (this.value == '') this.value = 'Mensagem';"
);
  echo form_textarea($data);
  
  $data = array(
"name" => "ContactSubmit",
"id" => "ContactSubmit",
"value" => "Enviar",
"class" => "btn btn-success"
  );

echo form_submit($data);

$data = array(
"name" => "Reset",
"id" => "Reset",
"value" => "Limpar",
"class" => "btn dark_btn",
"style" => "margin-left: 10px"
  );

echo form_reset($data);

echo form_close();

          ?>

And below's the controller, containing the submit function:
Code:
public function send_email()
{
  $this->load->helper(array('form', 'url'));
  $this->load->library("form_validation");
  
  $this->form_validation->set_rules('name', 'Nome', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');
  $this->form_validation->set_rules('message', 'Mensagem', 'required');
  
  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('error');
  }
  else
   $this->load->view('success');

}

Every time I click on the submit button, it goes to success page even though I didn't fill up anything in the form. I believe that field names are correct, so I really don't understand what's causing this issue.

As a probably related note, I'm using a htaccess file to remove the index.php from the url, along with some routes:
Code:
$route['about'] = 'welcome/about';
$route['home'] = 'welcome/index';

Besides, I'm using partial views, so this form is actually placed inside one, called footer.
I've read this thread(http://stackoverflow.com/questions/9126114/codeigniter-form-showing-validation-error-of-a-view-within-another-view) which seems to present a similar problem, but couldn't solve it thus far.

Any thoughts?

Sincerely,
Apidcloud


Form Validation Run returning true every time - El Forum - 10-02-2014

[eluser]Apidcloud[/eluser]
Omg. I was setting the property value for each input type..hence returning true all the type.

Damn, wasted around 2 or 3 hours.

Thanks anyway