How can I send two values with one button?

peace_love picture peace_love · May 17, 2016 · Viewed 13.7k times · Source

Is it possible to submit two values from one button?

$orderby = $_GET['orderby'];

<form action="mypage.php" method="get">
<a><button name ="orderby" value="name" type="submit">&#9660;</button></a>
<a><button name ="orderby" value="age" type="submit">&#9660;</button></a>
</form>

I imagine something like this:

<a><button name ="orderby" value1="name" value2="ASC" type="submit">&#9660;</button></a>
<a><button name ="orderby" value1="name" value2="DESC" type="submit">&#9660;</button></a>
<a><button name ="orderby" value1="age" value2="ASC" type="submit">&#9660;</button></a>
<a><button name ="orderby" value1="age" value2="DESC" type="submit">&#9660;</button></a>

Answer

Sebastian Brosch picture Sebastian Brosch · May 17, 2016

You can use a hidden field with <input type="hidden"/>:

<?php
    $orderby = $_GET['orderby'];
?>
<form action="mypage.php" method="get">
    <input type="hidden" name="field" value="fieldname"/>
    <input type="hidden" name="orderby" value="<?= $orderby ?>"/>
    <button name ="submit" value="1" type="submit">&#9660;</button>
</form>