Apologies if it's a stupid but it's been a long day. So my form look something like this...
<form action="/basket.php" method="get">
.co.uk
<select name="years">
<option value="1">1 year</option>
<option value="2">2 years</option>
<option value="3">3 years</option>
<option value="4">4 years</option>
<option value="5">5 years</option>
</select>
<input type="checkbox" name="url" value=".co.uk">
<br>
.com
<select name="years">
<option value="1">1 year</option>
<option value="2">2 years</option>
<option value="3">3 years</option>
<option value="4">4 years</option>
<option value="5">5 years</option>
</select>
<input type="checkbox" name="url" value=".com">
<button type="submit">
</form>
Let say I only ticked the .com
parameter and changed the years to 3 years.. I would currently get the URL as follows:
/basket.php?years=1&url=.com&years=3
What I would like is...
/basket.php?url=.com&years=3
The actually form contains more choices but I only want to submit the 'lines' that have the final checkbox ticked.
Hope this make sense! Many thanks in advance.
First of all, if your two checkboxes are mutually exclusive, you want to be using radio buttons so that only one can be checked, like so:
<input type="radio" name="url" value=".com"/>
<input type="radio" name="url" value=".co.uk"/>
Assuming you're looking for a PHP solution rather than one which uses JavaScript, I would suggest having your form POST
to basket.php
, which should determine which inputs to keep based on the value of $_POST['url']
, and then redirect with the corresponding years
value.
Also note that you should use a different name
for your select
elements so that they can be distinguished between.
That being said, the best option would be to use two form
elements, but this would require either two submit buttons, or JavaScript to perform the submission.
Also, if they both share the same options for years
, you could remove the duplicate select
to make things easier.