Simon Leung
asked on
PHP button action
There are two buttons in PHP. If user click button 1, it will go to action1.php. If user click button2, it will go to action2.php
Any idea how to code it ?
Thx
Any idea how to code it ?
Thx
you can simply use JavaScript to achieve that, like:
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<button type="button" onclick="doPost(this)">action1.php</button>
<button type="button" onclick="doPost(this)">action2.php</button>
</form>
</body>
</html>
<script language="javascript">
function doPost(c) {
alert(c.textContent);
c.form.action = c.textContent;
c.form.submit();
}
</script>
ASKER
can it be handled simply with HTML and php ?
Thx again.
Thx again.
try something like this:
<?php
if (isset($_POST['action'])) {
echo $_POST['action'];
header("Location: ".$_POST['action']);
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<button type="submit" name="action" value="action1.php">Submit to action1.php</button>
<button type="submit" name="action" value="action2.php">Submit to action2.php</button>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx
Please share some code - are you talking about a form or links here?