CodeIgniter Forums

Full Version: Form_validation doesn't work ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

I have controller with method:
PHP Code:
public function AddPost() {

 if ( isset( 
$_POST ) ) {

 
$this->form_validation->set_rules('TitlePostField''Tytuł''trim|required|xss_clean');
 
$this->form_validation->set_rules('AliasPostField''Alias postu''trim|xss_clean');
 
$this->form_validation->set_rules('ContentPostField''Treść postu''trim|required|xss_clean');

 if ( 
$this->form_validation->run() == FALSE ) {
 
$User $this->ion_auth->user()->row(); 

 if ( !empty( 
$this->input->post'AliasPostField' ) ) ) {
 
$alias str_replace" ""-"$this->input->post'AliasPostField' ) );
 } else {
 
$alias str_replace" ""-"$this->input->post'TitlePostField' ) );
 }

 if ( empty( 
$this->input->post'StatusPostField' ) ) ) {
 
$status 0;
 } else {
 
$status 1;
 }

 
$data = array(
 
'alias' => $alias,
 
'date' => time(),
 
'autor' => $User->first_name ' ' $User->last_name,
 
'rank' => $User->rank,
 
'title' => $this->input->post'TitlePostField' ),
 
'content' => $this->input->post'ContentPostField' ),
 
'status' => $status,
 );

 if ( 
$this->Posts_model->AddPost$data ) ) {
 
$this->session->set_flashdata('msg''<strong>Pomyslnie!</strong> Wpis został dodany!');
 
redirect'panel/front-page','refresh' );
 }

 }

 }

 } 

but form_validation not working.

In autoload I have:
PHP Code:
$autoload['libraries'] = array( 'database''email''form_validation''ion_auth' ); 
PHP Code:
$autoload['helper'] = array( 'url''form' ); 
I think their is a small issue with the logic in your controller. Try:
Code:
$this->form_validation->run() !== FALSE

One other thing I noticed is that your should not use xss_clean this way. From the documentation: XSS escaping should be performed on output, not input!
(08-16-2015, 01:00 PM)Diederik Wrote: [ -> ]I think their is a small issue with the logic in your controller. Try:
Code:
$this->form_validation->run() !== FALSE

One other thing I noticed is that your should not use xss_clean this way. From the documentation: XSS escaping should be performed on output, not input!

Ok, now it's ok, but is another problem ... I don't have messages with errors. I write in my controller:
PHP Code:
$this->form_validation->set_message('required''Error Message'); 

and in view:
PHP Code:
echo validation_errors() 

But I don't getting errors
Perhaps you should read the documentation. It has got tons of examples which should get you up on your feet.

http://www.codeigniter.com/userguide3/li...ation.html