Welcome Guest, Not a member yet? Register   Sign In
form_validation doesn't show errors
#1

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)
Reply
#2

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.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#3

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
Reply
#4

(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
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#5

(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
Reply
#6

(This post was last modified: 02-14-2015, 02:03 PM by RobertSF.)

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.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#7

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.
Reply
#8

Yes, but your general advice was still correct -- use var_dump instead of echo.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB