Welcome Guest, Not a member yet? Register   Sign In
Better than if(count($_POST) > 0)
#11

[eluser]veledrom[/eluser]
So which one do you prefer guys? Best practise, most reliable and fastest.


Code:
<input type="submit" name="submit_button" value="Login"  />

Code:
if($this->input->post('submit_button') == 'Login') {
// do something
}

if(! empty($_POST)) {
// do something
}

if(count($_POST) > 0)
{
// do something
}

if(! empty($_POST['submit_button']))
{
// do something
}

if(isset($_POST["submit_button"]))
{
// do something
}
#12

[eluser]Mauricio de Abreu Antunes[/eluser]
Code:
if($this->input->post('submit_name')) {
// do something
}
This one!
#13

[eluser]veledrom[/eluser]
[quote author="Mauricio de Abreu Antunes" date="1330707497"]
Code:
if($this->input->post('submit_name')) {
// do something
}
This one![/quote]

This way doesn't work.
Code:
if(! $this->input->post('submit_name')) {
// do something
}
#14

[eluser]johnpeace[/eluser]
[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
}
#15

[eluser]John Murowaniecki[/eluser]
It smells like some XGH proccess, not?
#16

[eluser]Mauricio de Abreu Antunes[/eluser]
^
Yep!

Main question to author:
Why are you trying to check if form was submmited?
#17

[eluser]Matalina[/eluser]
[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.
#18

[eluser]johnpeace[/eluser]
Yah, I didn't verify whether veledrom's code did or didn't work. According to the docs:

Quote:The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.

So apparently yes, that is wrong.

I check for the value coming in the $_POST array to match the value I'm expecting <shrug>
#19

[eluser]Matalina[/eluser]
which is wrong? with or with out the ! (not)
#20

[eluser]sarcastron[/eluser]
You can also use the input->post() method without any arguments.

Code:
$post = $this->input->post();
if ($post) {
    // the form was submitted, do something...
}

or for redirecting

Code:
$post = $this->input->post();
if ( ! $post) {
    // post is required for this page, redirect them
    redirect('some/other/page');
}




Theme © iAndrew 2016 - Forum software by © MyBB