Adam
asked on
How can I carry out two action through one form (with one button) in php?
Hello,
I want to send a form with two actions. Those actions are to send two different values to another (the same) page. As individual actions these send but it's when I try to combine thw two actions into one form that I have problems.
Something like this -
However, from a bit of googling, I understand that a form can only send one action. From a bit of a reading online I made a number of failed attempts along these lines using input type 'hidden':
And then tried to pick up the posted values in addfav.php with the following
This doesn't work - Nothing happens when I press the button.
Is it correct that a form can't sent two actions, and if so, is using input type 'hidden' the correct method moving forward? I'm trying to stick to using php and avoiding javascript if possible. Any help, advice greatly appreciated as always.
Many thanks for reading.
Adam
I want to send a form with two actions. Those actions are to send two different values to another (the same) page. As individual actions these send but it's when I try to combine thw two actions into one form that I have problems.
Something like this -
<form action="<?php echo 'addfav.php?id='. $teacher['id'] ;?>"
<form action="<?php echo 'addfav.php?ids='. $_SESSION['session_ids'];?>" method="post">
However, from a bit of googling, I understand that a form can only send one action. From a bit of a reading online I made a number of failed attempts along these lines using input type 'hidden':
<form id="form" name="form" method="post" action="addfav.php">
<input type="button" class="btn btn-info btn-sm" />
<input type="hidden" name="teacherid" id="teacherid" value="<?php echo $teacher['id'] ;?>">
<input type="hidden" name="studentid" id="studentid" value="<?php echo $_SESSION['session_ids'];?> ">
</form>
And then tried to pick up the posted values in addfav.php with the following
<?php if ((isset($_POST['teacherid']) && $_POST['teacherid'] != "") && (isset($_POST['studentid']) && $_POST['studentid'] != "")){
$studentid = $_POST['studentid'];
$teacherid = $_POST['teacherid'];
}
?>
This doesn't work - Nothing happens when I press the button.
Is it correct that a form can't sent two actions, and if so, is using input type 'hidden' the correct method moving forward? I'm trying to stick to using php and avoiding javascript if possible. Any help, advice greatly appreciated as always.
Many thanks for reading.
Adam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Have a great evening.