Useful_Investigator
Useful_Investigator

Reputation: 948

PHP, html: How to pass the button value to post

I'm trying to pass in the value of the button to $_POST["class_name"] so I can use it in selectclass.php. I want to be able to click on the button in the table and have $_POST = the value of the button, or even better, if possible, the class_id next to the button. Any help would be really appreciated.

 <tbody>
            <form action="selectclass.php" method="post">
            <?php foreach ($classes as $class): ?>

                <tr>

                  <th><button type="text" name = "class_id"><?=$class["class_name"]?></button></th>
                  <th><?=$class["class_id"] ?></th>

                </tr>

         <?php endforeach ?>
         </form>
        </tbody>

Upvotes: 2

Views: 2553

Answers (1)

John Conde
John Conde

Reputation: 219804

If you want it to have a value, give it one using the value attribute:

<button type="text" name="class_id" value="some_value">

See <button> on MDN

Upvotes: 2

Related Questions