Reza
Reza

Reputation: 880

form get method removes url parameter after form submit

I am making custom data filters for my script. All works fine except for 1 filter.

I have a option to view all data of today so if you go to my-url.file.php?view=today

it knows it has to fetch all data for today. But next to date filters I have also some other filters. Which can be set through GET (form)

everything works but when I'm viewing my-url.file.php?view=today and set (for example) a sort filter it redirects to ?p=5&limit=3&ordersort=orderdesc but it should redirect to ?p=5&**view=today**&limit=3&sortby=orderdesc

so I thought.. Ok let me set the action through a var and check if the page is view today if so.. I'm going to put the ?view in the url otherwise not.. but still it removes this var

what is the best way to approach this?

<?php
if (isset($_GET['view']) && $_GET['view'] === 'today')
    {
        $action = "adminOrders.php?view=today";
    }
else 
    {
        $action = "adminOrders.php";
    }
?>
<form name="ordermanage" method="get" action="<?php echo $action; ?>">  
  <label>Show &nbsp;
    <select id="form-field-select-1" class="form-control" style="display: inline-block !important;width:100px !important" id="limit" name="limit" onchange="document.ordermanage.submit();">
      <option value="50"  <?php echo (Input::get('limit') == 50) ? 'selected="selected"' : ''; ?>>50</option>
      <option value="100" <?php echo (Input::get('limit') == 100) ? 'selected="selected"' : ''; ?>>100</option>
      <option value="200" <?php echo (Input::get('limit') == 200) ? 'selected="selected"' : ''; ?>>200</option>
      <option value="300" <?php echo (Input::get('limit') == 300) ? 'selected="selected"' : ''; ?>>300</option>
    </select> &nbsp;orders&nbsp;&nbsp;&nbsp;&nbsp;</label>

  <label>Sort by &nbsp;
    <select id="form-field-select-1" class="form-control" style="display: inline-block !important;width:200px !important" id="ordersort" name="ordersort" onchange="document.ordermanage.submit();">
      <option value="orderdesc"  <?php echo ($selectBoxVarSort === "orderdesc") ? 'selected="selected"' : ''; ?>>Ordernr high to low</option>
      <option value="orderasc" <?php echo ($selectBoxVarSort === "orderasc") ? 'selected="selected"' : ''; ?>>Ordernr low to high</option>
      <option value="pricedesc" <?php echo ($selectBoxVarSort === "pricedesc") ? 'selected="selected"' : ''; ?>>Price high to low</option>
      <option value="priceasc" <?php echo ($selectBoxVarSort === "priceasc") ? 'selected="selected"' : ''; ?>>Price low to high</option>
    </select>
  </label>
</form>

Upvotes: 0

Views: 2978

Answers (2)

Stupidus
Stupidus

Reputation: 3

Have you tried to add an hidden input into the form with the name "view" and the value "today" ?

Upvotes: 0

akirk
akirk

Reputation: 6837

If you specify the form method GET, the parameter in the action will be overridden. You can solve this using a hidden form field:

<form name="ordermanage" method="get" action="adminOrders.php">
<?php
if (isset($_GET['view']) && $_GET['view'] === 'today') {
    ?><input type="hidden" name="view" value="today" /><?php
}
?>
<label>Show &nbsp;

Upvotes: 7

Related Questions