[eluser]CroNiX[/eluser]
[quote author="Matalina" date="1330714451"][quote author="johnpeace" date="1330708813"][quote author="veledrom" date="1330708084"]
This way doesn't work.
Code:
if(! $this->input->post('submit_name')) {
// do something
}
[/quote]
This does though:
Code:
if($this->input->post('submit_button') != 'Login') {
// do something
}
[/quote]
I do it all the time The above quoted code is wrong tho there is no !
Code:
if($this->input->post('submit_name')) {
// do something
}
if $this->input->post('submit_name') has something in it it will return TRUE because it's not empty if('hi') is always true.
[/quote]
This is not exactly true. If there is not a post value (like a checkbox that isn't checked doesn't get sent in POST), input::post('field_name') returns boolean FALSE. If it
does exist, it will return the
value of that field (not TRUE as stated above). It's best to use the === operator because if the value of the field is an actual 0, then if($this->input->post('field_name')) will evaluate to FALSE even though the field value was sent and is a zero.
I usually use
Code:
$submitted = $this->input->post('name_of_submit_button');
if ($submitted !== FALSE)
{
// Form was submitted, set up validation rules and run validation
// Inefficient setting up and running validation if form was not submitted.
}
else
{
// Form was not submitted
}