PHP Form Introduction Getting User Information Text Input

  • Slides: 20
Download presentation
PHP Form Introduction Getting User Information Text Input

PHP Form Introduction Getting User Information Text Input

Handling User Input • In this example we will have two files. – For

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.

Make an HTML file like that below.

The code behind so far

The code behind so far

Add the <form> tag with name, action and method attributes

Add the <form> tag with name, action and method attributes

Another approach: Insert/Form

Another approach: Insert/Form

Supply action, method and name attributes

Supply action, method and name attributes

Any input element should be between the <form> tags, so I moved the close

Any input element should be between the <form> 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

Highlight both cells in the seconds row and then go to Modify/Table/Merge cells

Enter Text in the table cells

Enter Text in the table cells

Go to Insert/Form/Text Field

Go to Insert/Form/Text Field

Supply an id and a tab index. (The label is for associated text, but

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

Result (with size attribute) in code and design Note the name and id attributes are both set to txt. First. Name. Java. Script usually uses id and PHP uses name.

Add another input text field, then place the cursor after the table but inside

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

Enter value for the type, name and value

Submit code in Code and Design

Submit code in Code and Design

Adding some style to the button

Adding some style to the button

Starting the PHP code that handles the form data This code takes the data

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 $first. Name and $last. Name. Remember PHP variables start with a dollar sign.

Code to display user’s information This code uses the concatenation operator, which in PHP

Code to display user’s information This code uses the concatenation operator, which in PHP is a period.

Form and Form handler

Form and Form handler