Home > Back-end >  Multiple buttons but one text input html/php
Multiple buttons but one text input html/php

Time:10-27

So let's say you have a little form in html with a text input and a submit button, just like this:

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

    </body>
    </html>

How would i add another button and index.php would know what button i pressed?
Also, what i'm trying to do is make the php execute some python code that i have in another file but i know how to do that already.

Edit: I would like my php to know what button was pressed, if encode was pressed, run some code, if decode was pressed, run some other code.

CodePudding user response:

Let me know is it what you want?

You can simply add a one if in php and simple pass name in form when button clicked then code inside if condition executed.

PHP code:

<?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>

Ping me if you want something else

  • Related