How to Pass the Button Value As a Hidden Field in PHP
- 1). Right-click the HTML page that contains the form button. Click "Open With," then click the HTML editor you prefer to use for your website code.
- 2). Scroll down the page and create an HTML hidden field that matches the value of your button. The following code shows you a button field with a hidden field underneath that contains the same value:
<input type="button" value="xyz">
<input type="hidden" value="xyz"> - 3). Right-click your PHP processing page and select "Open With." Click the PHP editor in the list of programs to load the PHP code in the editor.
- 4). Type the PHP processing code. For instance, the following code retrieves the hidden field's value and displays it to the user:
echo $_POST['myvar'];
Notice the PHP code retrieves the hidden tag and not the button tag's ID. Replace "myvar" with the name of your own hidden tag created in the HTML code.