多个按钮,但一个文本输入 html/php

Multiple buttons but one text input html/php

假设您在 html 中有一个带有文本输入和提交按钮的小表单,就像这样:

        <html>
        <body>
        
        <form action="index.php" method="post">
        Text to encode/decode: <input type="text" name="textoencode"><br>
       <input type="submit">
        </form>
    
        </body>
        </html>

如何添加另一个按钮并且 index.php 知道我按下了哪个按钮?
另外,我想做的是让 php 执行我在另一个文件中的一些 python 代码,但我已经知道该怎么做了。



编辑:如果按下编码,我希望我的 php 知道按下了什么按钮,如果按下解码,运行 一些代码, 运行 一些其他代码。

告诉我这是你想要的吗?

您可以简单地在 php 中添加一个 if 并在单击按钮时在表单中简单地传递名称然后执行 if condition 中的代码。

PHP代码:

<?php
if (isset($_POST['phpbutton'])) {
    // Your code that you want to execute
}
?>

HTML:

<html>
    <body>
    
    <form action="index.php" method="post">
    Text to encode/decode: <input type="text" name="textoencode"><br>
   <input type="submit">
   <button type="submit" name="phpbutton">press me</button>
    </form>

    </body>
    </html>

如果你想要别的东西请联系我