In my form there are multiple submit buttons and each submit button should redirect the page to same location but the content changes based on the session variable set. But writing isset();
for each submit button is difficult. So I am trying to write a loop where foreach input type submit the loop should write the isset();
function.
My form is like:
<form method="POST">
<input type="submit" name="type1" value="type1" > <br/>
<input type="submit" name="type2" value="type2" >
</form>
And I have tried to mix up JQUERY with PHP to achieve this, like:
<?php
echo '<script>
$("input:submit").each(function(){
var inputName = $(this).attr("name");' ;
$inputName = print 'document.write(inputName);';
if(isset($_POST[$inputName])){
$_SESSION["value"] = $inputName;
header('Location:somepage.php');
}
echo ' });
</script>';
?>
But this is not working.
Kindly help me to achieve the loop foreach input which has type as submit.