I have a form:
<form action="results.php" method="get">
<select name="genres[]">
<option value="jazz"></option>
<option value="blues"></option>
<option value="rock"></option>
</select>
</form>
After submitting the form, in the URL the input becomes example.com/?genres%5B%5D=jazz&genres%5B%5D=blues&genres%5B%5D=rock
Next to that it doesn't look very nice, I have multiple inputs in my form (and around 18 genres) so if a user selects a lot, the URL becomes very long. I'd like it to become /?genres=jazz,blues,rock
Now I've read this post, but it doesn't state how to make the cleaner URL. Next to that, I have to use the input as an array, eg $genres = $_GET['genres']
to use in another function.
you can do it like this:
in results.php you should:
i have removed the form completely because the genres are now sent by
document.location.href
. The.val()
function of jquery returns the selected values like expected (imploded by,
)