php form introduction getting user information text input

20
PHP Form Introduction Getting User Information Text Input

Upload: berniece-bryant

Post on 04-Jan-2016

226 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: PHP Form Introduction Getting User Information Text Input

PHP Form Introduction

Getting User Information

Text Input

Page 2: 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.

Page 3: PHP Form Introduction Getting User Information Text Input

Make an HTML file like that below.

Page 4: PHP Form Introduction Getting User Information Text Input

The code behind so far

Page 5: PHP Form Introduction Getting User Information Text Input

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

Page 6: PHP Form Introduction Getting User Information Text Input

Another approach: Insert/Form/Form

Page 7: PHP Form Introduction Getting User Information Text Input

Supply action, method and name attributes

Page 8: PHP Form Introduction Getting User Information Text Input

Any input element should be between the <form> tags, so I moved the close form tag to the bottom of the page.

Page 9: PHP Form Introduction Getting User Information Text Input

Highlight both cells in the seconds row and

then go to Modify/Table/Merge cells

Page 10: PHP Form Introduction Getting User Information Text Input

Enter Text in the table cells

Page 11: PHP Form Introduction Getting User Information Text Input

Go to Insert/Form/Text Field

Page 12: PHP Form Introduction Getting User Information Text Input

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.

Page 13: PHP Form Introduction Getting User Information Text Input

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.

Page 14: PHP Form Introduction Getting User Information Text Input

Add another input text field, then place the cursor after the table but inside the form and go to Insert/Form/Button

Page 15: PHP Form Introduction Getting User Information Text Input

Enter value for the type, name and value

Page 16: PHP Form Introduction Getting User Information Text Input

Submit code in Code and Design

Page 17: PHP Form Introduction Getting User Information Text Input

Adding some style to the button

Page 18: PHP Form Introduction Getting User Information Text Input

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.

Page 19: PHP Form Introduction Getting User Information Text Input

Code to display user’s information

This code uses the concatenation operator, which in PHP is a period.

Page 20: PHP Form Introduction Getting User Information Text Input

Form and Form handler