Keeping the previous one when adding a new one to the form

I have this form that comes with some options from another page. I want to keep these values ​​and add the sortby parameter, but every time I click, all the parameters disappear, but the new sortby parameter.

How do I keep the parameters from the previous page and add or change only the orderby parameter.

<form name="formSearch" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>"  method="GET">
    <select name="order_by" id="order_by">
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 1) { echo "selected"; } ?> value="1">Ultima Modificacion (Reciente)</option>
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 2) { echo "selected"; } ?> value="2">Ultima Modificacion (Viejo)</option>
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 3) { echo "selected"; } ?> value="3">Precio (Mayor to Menor)</option>
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 4) { echo "selected"; } ?> value="4">Precio (Menor to Mayor)</option>
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 5) { echo "selected"; } ?> value="5">Marca/Modelo (A to Z)</option>
        <option <?php if( isset($_REQUEST['order_by']) && $_REQUEST['order_by'] == 6) { echo "selected"; } ?> value="6">Marca/Modelo (Z to A)</option>
    </select>
    <input name="submit" type="submit" />
</form>

      

+2


source to share


3 answers


Add to

<INPUT type='hidden' name='OPT1' VALUE='<?php if( isset($_REQUEST['OPT1'])) { echo $_REQUEST['OPT1']; } else { echo "" } ?>

since you need to pass them as hidden input fields.

OPT1 is the name of the saved parameter - add as many as you have parameters



If you want the fields / values ​​to actually be displayed then:

  • Drop type='hidden'

    to display and be editable

  • Make them locked input fields so they can be displayed and not edited.

However, these two options need to be done cleanly, for example. if the old value came up with a radio button, you need to display and preset the same radio button setting, etc.

+1


source


The "form" method seems to work if you use the "GET" method. So, if I need to store values ​​and need to use "GET", I will need to add a bunch of hidden fields like this was suggested. But I tried to avoid it. If anyone knows a better way, please let me know if this wasn't a solution:

"method =" GET ">

$ V) {echo ''. "\ n"; }? >

Now, if you don't need to use "GET" on the result form, just change the method to "POST" and it will work fine.



Please note that if you came from another form, this form must be "GET" for this.

Search Page -> Use Get Results Page with Sort Form -> Use Post

0


source


The easiest way to save data is to make sure that the fields responsible for filling in the appropriate values ​​are present on the current page. If they should no longer be visible to the user on the page in question, you can set them to <input type="hidden" name=fieldname" value="value_set_on_previous_submit"/>

. Or, if they still have to show, just make sure their values ​​are set to the ones sent.

-1


source







All Articles