Assuming I have the following form:
<form action="process.php">
<input type="checkbox" name="option1" value="oats"> Oats
<input type="checkbox" name="option2" value="beans"> Beans
<input type="hidden" name="parameter" value="a"/>
<input type="submit" value="Submit"/>
</form>
What would normally happen is after clicking on the URL, the browser redirects to:
process.php?option1=oats&option2=beans¶meter=a
How do I make it such that when the submit is clicked all the checkboxes end up as part of the "parameter", but separated by commas? So in other words it would be:
process.php?parameter=a,oats,beans
Best solution with minimal javascript/jquery/html is best if no html solution.
When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input types: email, and file. Tip: For <input type="file"> : To select multiple files, hold down the CTRL or SHIFT key while selecting.
Parameters are passed to the web application as part of an HTTP request in the form of ”name=value” strings. When multiple parameters are required they are delimited by the '&' character.
If you want several values in one parameter, you have to name it like parameter[]
f.e.:
<form action="process.php">
<input type="checkbox" name="parameter[]" value="oats"> Oats
<input type="checkbox" name="parameter[]" value="beans"> Beans
<input type="hidden" name="parameter[]" value="a"/>
<input type="submit" value="Submit"/>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With