CodeIgniter Forums
form_validation doesn't show errors - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: form_validation doesn't show errors (/showthread.php?tid=1136)



form_validation doesn't show errors - vertisan - 02-13-2015

Hi!

I have problem with Form Validation from CI 3.0 RC2.
I have method in controller:
PHP Code:
public function dodaj()
 {
// ...
 
if ( !empty( $_POST ) )
 {
 
 
$this->form_validation->set_rules('imie_wolont''Imie wolontariusza''trim|required');
 
$this->form_validation->set_rules('d_imie_wolont''Drugie mie wolontariusza''trim|required');
//etc 

 
if ($this->form_validation->run() == TRUE) {
 
 
$dodaj_wolont = array(
 
'imie' => $this->input->post'imie_wolont' ),
 
'drugie_imie' => $this->input->post'd_imie_wolont' ),
// etc
 
);

 
$this->Wolontariusze_model->dodaj'wolontariusze' $dodaj_wolont );
 }
 } 

and view with:
PHP Code:
echo validation_errors(); 
but i don't getting errors, why? (I have form and form_validation in autoload)


RE: form_validation doesn't show errors - RobertSF - 02-13-2015

Everything looks ok, but here are some ideas.

Are the set_rules statements executing? Check with an echo statement.
Does the run() statement really return TRUE? Check with an echo statement.
Try the rules with only 'required' and see if anything changes.


RE: form_validation doesn't show errors - Narf - 02-13-2015

My guess is that you're submitting an empty form, which also means an empty $_POST and with your code - even the rules aren't set under that condition.

(02-13-2015, 06:36 PM)RobertSF Wrote: Does the run() statement really return TRUE? Check with an echo statement.

echo TRUE; will echo nothing. Smile


RE: form_validation doesn't show errors - RobertSF - 02-13-2015

(02-13-2015, 06:49 PM)Narf Wrote: echo TRUE; will echo nothing. Smile

Ha, ha, ha, true! But...
PHP Code:
$x $this->form_validation->run();
echo 
$x



RE: form_validation doesn't show errors - Narf - 02-14-2015

(02-13-2015, 09:33 PM)RobertSF Wrote:
(02-13-2015, 06:49 PM)Narf Wrote: echo TRUE; will echo nothing. Smile

Ha, ha, ha, true! But...

PHP Code:
$x $this->form_validation->run();
echo 
$x

What won't echo anything either ... echo prints strings and CI_Form_validation::run() returns a boolean. Any time you cast a boolean to string (in this case, there's an implicit cast), it will become an empty string.

var_dump() should help. Smile


RE: form_validation doesn't show errors - RobertSF - 02-14-2015

var_dump is definitely the way to go.

But just to clarify, only FALSE results in an empty string. Echoing TRUE outputs 1 to the screen.

Still, using var_dump is better than using echo, no doubt about it.


RE: form_validation doesn't show errors - Narf - 02-14-2015

Hmm ... seems that you are correct.
Quite weird, but true - echoing TRUE does result in 1 being printed.

Anyway, enough of that - sorry for the noise.


RE: form_validation doesn't show errors - RobertSF - 02-14-2015

Yes, but your general advice was still correct -- use var_dump instead of echo.