假设您希望创建一个HTML/PHP脚本,该脚本生成一个包含2个按钮的网页,点击该按钮时,会告诉您哪个按钮已被点击。这样做,使用PHP,我知道的,唯一的方法是创建索引文件提交按钮是执行php文件的唯一方法吗?
<? include('buttons.php'); ?>
<? include('clicked.php'); ?>
凡buttons.php保存在同一目录下,并包含
<form method="post">
<input type="submit" name="button1" value="button1">
<input type="submit" name="button2" value="button2">
</form>
而且PHP脚本点击.php包含
<?php
if($_POST['button1']){
echo "You have clicked button1";
}
elseif($_POST['button2']){
echo "You have clicked button2";
}
?>
此方法的工作原理,但我怀疑这不是使用PHP获得此结果的最佳方式。
有没有更好的方法来做到这一点?
你已经在做正确的事 –
你也可以使用一个参数,即链接。 '...'并检查if(isset($ _ GET ['action'])){if($ _ GET ['action'] =='button1'){} elseif($ _ GET ['action'] ==' button2'){}' – Sean
你的问题是,有没有其他方式做到这一点,因为这似乎是调用PHP代码的正常方式。 –