PHP Form Introduction Getting User Information Text Input
Handling User Input In this example we will have two files. –For simplicity sake the first one will be an HTML file known as a form (it will have no PHP code). –The second file will be a PHP file that has variables that get their values from data entered by the user on the first file.
Make an HTML file like that below.
The code behind so far
Add the tag with name, action and method attributes
Another approach: Insert/Form/Form
Supply action, method and name attributes
Any input element should be between the tags, so I moved the close form tag to the bottom of the page.
Highlight both cells in the seconds row and then go to Modify/Table/Merge cells
Enter Text in the table cells
Go to Insert/Form/Text Field
Supply an id and a tab index. (The label is for associated text, but we placed that in another table cell.) The tab index will allow the user to click the tab button to progress through the form without using a mouse.
Result (with size attribute) in code and design Note the name and id attributes are both set to txtFirstName. JavaScript usually uses id and PHP uses name.
Add another input text field, then place the cursor after the table but inside the form and go to Insert/Form/Button
Enter value for the type, name and value
Submit code in Code and Design
Adding some style to the button
Starting the PHP code that handles the form data This code takes the data associated with the form and its post method and assigns the values to the PHP variables $firstName and $lastName. Remember PHP variables start with a dollar sign.
Code to display user’s information This code uses the concatenation operator, which in PHP is a period.
Form and Form handler