How can I send two values with one button?
15,520
Solution 1
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">▼</button>
</form>
Solution 2
you have to to use inside the form
<form>
<input type=hidden name=var1 value="value1">
<input type=hidden name=var2 value="value2">
<input type=hidden name=var3 value="value3">
Solution 3
Send it through the URL eg.
<form action="mypage.php?orderby=name&order=ASC" method="get">
<a><button name ="orderby" value="name" type="submit">▼</button></a>
</form>
Solution 4
If you want to use the button for get values, you can use jquery and ajax. A sample code is given below
$(form).on('submit', function(e){
e.preventDefault();
var value1 = $('button[name=orderby]').attr('value1');
var value2 = $('button[name=orderby]').attr('value2');
$.ajax({
url: 'your/url',
type: 'POST',
data: {
value1: value1,
value2: value2
},
success: function(data){
//success action
},
error: function(){
//error action
}
});
});
Solution 5
Use like "name ASC
" or "name{splitter}ASC
" and explode it to use in your code
<a><button name ="orderby" value="name ASC" type="submit">▼</button></a>
<a><button name ="orderby" value="name DESC" type="submit">▼</button></a>
<a><button name ="orderby" value="age ASC" type="submit">▼</button></a>
<a><button name ="orderby" value="age DESC" type="submit">▼</button></a>
Comments
-
peace_love almost 2 years
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">▼</button></a> <a><button name ="orderby" value="age" type="submit">▼</button></a> </form>
I imagine something like this:
<a><button name ="orderby" value1="name" value2="ASC" type="submit">▼</button></a> <a><button name ="orderby" value1="name" value2="DESC" type="submit">▼</button></a> <a><button name ="orderby" value1="age" value2="ASC" type="submit">▼</button></a> <a><button name ="orderby" value1="age" value2="DESC" type="submit">▼</button></a>
-
peace_love almost 8 yearsI have multiple submit buttons in one form
-
Mischa Mustermann over 2 yearsThats usefull if you have a FORM and you need to submit in a FORM another two or more values and you cant create another FORM in the existing FORM.