Php, mysq lpart4(processing html form)

15
Processing HTML FORM Author:- Subhasis CMC

description

how to gwhow to validate php form

Transcript of Php, mysq lpart4(processing html form)

Page 1: Php, mysq lpart4(processing html form)

Processing HTML FORM

Author:- Subhasis

CMC

Page 2: Php, mysq lpart4(processing html form)

The form code looks as like below

Page 3: Php, mysq lpart4(processing html form)

Output of the code will be

Page 4: Php, mysq lpart4(processing html form)

html form tagsForm Tags Output

<input type = "text" name = "name"/>

<input type="radio" name ="gender" value ="m“/>

<input type="CHECKBOX" name="age" value ="Y" checked/>

<SELECT name = "education"><option selected value=“pg">P.Graduate</option>

</SELECT>

<input type="submit" name="submit" value="submit">

<TEXTAREA name = "aboutu" rows ="5" cols ="28" ></TEXTAREA>

Page 5: Php, mysq lpart4(processing html form)

Main form tag

• Method =“post” – This is the way of processing our userfilled data into the form. Instead of „POST‟ we can use„GET‟.

• GET – when we use get method the data processed willbe visible. The amount of data is to be sent is limited

• POST – when we use POST method the data processedwill be not visible. The amount of data is to be sent is notlimited.

Page 6: Php, mysq lpart4(processing html form)

Continue

• When we process the form the html sends the data to file which is inaction tag. Here when the form will process it will sends to“formfill.php”.

• We need some php code to get those values which will be sent by theform tag .

• We have three types.▫ $_GET = we used to get the values from html form when method is get▫ $_POST = we used to get the values from html form when method is

post▫ $_REUQEST = it works on both .

Page 7: Php, mysq lpart4(processing html form)

PHP code to get the form values

• In PHP the $_GET,$_POST & $_REQUEST arespecial array in PHP.

• It collect the information which filed has collectedthe values .

• Simply there is no value about the fields on whichthere is no values entered by the user.

• To check that use the step by step tutorial. I will use$_POST for this what ever you want you can referelse you can refer what I am referring.

Page 8: Php, mysq lpart4(processing html form)

Checking the Special array $_POST

• Step -1 :- write the html file with form as below.

Next step is to write aphp code for processing,the name will be inaction tag as below. Heremy php file name is“test.php”.Let‟s write that

Page 9: Php, mysq lpart4(processing html form)

Continue ….

• Step – 2 :- writing the php file “test.php”

Page 10: Php, mysq lpart4(processing html form)

What is $_POST,$_GET & $_REQUEST ?

• There are three special global arrays in PHP.

▫ $_POST

▫ $_GET

▫ $_REQUEST

• When ever you submit any data to get thosevalue you can use any one of the above array.

• $_POST is more robust than $_GET,$_REQUEST is combined both of them.

Page 11: Php, mysq lpart4(processing html form)

Cont’d……

• $_GET is not secured .

• $_GET is not capable to send large amount of

data

• $_POST is secured and able to send unlimitedamount of data.

• So $_POST is more preferable.

Page 12: Php, mysq lpart4(processing html form)

Let’s receive data sent by HTML form

• To fetch the data from form we have to specifyname for each element of the form.

• Once you do that any data you will send from

FORM it will be fetch by the special array$_GET & $_POST.

• To reuse it you can store it to some variable and

do what ever else you want to do.

Page 13: Php, mysq lpart4(processing html form)

An example(form code)

Page 14: Php, mysq lpart4(processing html form)

PHP code to process

Page 15: Php, mysq lpart4(processing html form)

Form validation