0

Apologies if this is a duplicate.

Below is how I pass a variable to my url;

<li><a href="blog-admin-users.php?source=add_users">Create Users</a></li>

From the above, my variable is source=add_users and so the page can get it by checking $_GET[source].

How do I achieve this with a html form.

My form below;

<form method="post" action="nextpage.php" class="search-form">
<div class="grid-33 tablet-grid-33 mobile-grid-100">
<label for="cuisine">LOCATION</label>
<br/>
<div class="select-wrapper">
<select name="location" id="location-select">
<option value="0">Central</option>
<option value="1">Garki</option>
</select>
</div>
</div>
<div class="grid-33 tablet-grid-33 mobile-grid-50">
<label for="day">DAY</label>
<br/>
<div class="select-wrapper">
<select id="activity" name="activity" onchange="changeTime(this);">
<option value="0">Central</option>
<option value="1">Garki</option>
</select>
</div>
</div>
<div class="grid-33 tablet-grid-33 mobile-grid-50">
<label for="time">TIME</label>
<br/>
<div class="select-wrapper">
<option value="0">Central</option>
<option value="1">Garki</option>
</select>
</div>
</div>
<div id="availability-container" class="grid-100">
<input class="find" type="submit" value="FIND FOOD" id="searchfood">
<div class="error" id="notification"></div>
</div>
</form>

When a user clicks on submit, I want it to navigate to page

http://www.test.com/nextpage.php?location=1&day=today&time=12:00

My form has 3 select tags I want to pass the option the user selected to the next page in the url so the next page can use $_GET to use them in a mysql query.

Thanks.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
moh_abk
  • 2,064
  • 7
  • 36
  • 65

2 Answers2

2

in your form action you can send GET values the same way.

<form method="POST" action="poop.php?poop=poop">
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
0

You have two options.

Option one is to change the form to method="get", and simply send everything as a $_GET request.

The second option is to append your $_GET to the end of the form's action. Since you specified that you want the user to be able to select which page they want to go to, you will need a bit of JavaScript.

In , you can change the form's action with the attr() method.

$('form').attr('action', 'nextpage.php?location=' + location + '&day=' + day + '&time=' + time);
Zsw
  • 3,920
  • 4
  • 29
  • 43