Welcome Guest, Not a member yet? Register   Sign In
Test multiple POST's with OR operator
#1

[eluser]mflammia[/eluser]
Hi,

Probably going about this completely wrong being a bit of a novice but I am trying to do something like the following:

Code:
if ($this->input->post('postcode'||'number'||'address1'||'address2'||'address3')){}

To test if anyone of these POSTS evaluates to true then continue.

Whats the best way to do this? Is there a codeigniter command that would help?

Many thanks in advance.
#2

[eluser]Kamarg[/eluser]
You need to repeat $this->input->post('var_name') for each of those. You can't use the || inside the variable name the way you're trying to (unless you extend the input class to process it how you want).

Code:
if ($this->input->post('postcode') || $this->input->post('number') || $this->input->post('address1') || $this->input->post('address2') || $this->input->post('address3')){}
#3

[eluser]aquary[/eluser]
"Maybe" possible by extending the input class to accept multiple parameters, and return the result as you expected. Though, you might have to think about flexibilities since sometime it might be useful to return array of values, not only TRUE or FALSE, or even return TRUE if "all" are posted.

There are a lot of possible way to do, but I think it's better to make a new method for input class to do this specific task instead.
#4

[eluser]mflammia[/eluser]
Thank you for the fast reply - taken info onborad.

Have repeated the code for now and will later optimise it with a new method.

#5

[eluser]porquero[/eluser]
maybe you should use a foreach:

Code:
$post_data = array('postcode', 'number', 'address1', 'address2', 'address3');
$result = false;

foreach($post_data as $input){
$result = $result || $this->input->post($input);
}

if ($result == true){}




Theme © iAndrew 2016 - Forum software by © MyBB