Welcome Guest, Not a member yet? Register   Sign In
change GET query string
#11

Another way to solve this, is assigning a default value to the fields. You probably let the user select the brand from a set of radiobuttons or a dropdown list. If no brand is selected, make the radiobutton "All brands" default (value "all"). Or in a dropdown list, set the default value to "all" with label "Select a brand...".
Now, when your form is transmitted, the get string has no empty options.
In the controller, check if the value of brand == 'all'. If so, you don't need a where clause in your query builder for that option.
Reply
#12

(This post was last modified: 01-26-2017, 04:31 AM by ivantcholakov. Edit Reason: a correction )

Code:
$query = array(
    'brand' => '',
    'model' => 'a',
);

$query = http_build_query(array_filter($query, 'strlen'));

$url = 'http://www.example.com'.($query != '' ? '?'.$query : '');

echo $url;
Reply




Theme © iAndrew 2016 - Forum software by © MyBB