Understanding PHP Form Creation for Beginners

php forms n.w
1 / 9
Embed
Share

"Learn how to create PHP forms step-by-step with Dr. John P. Abraham from UTRGV. Explore form attributes, methods, and differences between GET and POST requests. Enhance your knowledge in web development."

  • PHP Forms
  • Web Development
  • GET vs POST
  • Beginners
  • Form Attributes

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. PHP Forms Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314

  2. Begin with HTML <html> <head> </head> <body> <?php ?> <form> </form> </body> </html>

  3. Now add form under html <form action = "<?php $_PHP_SELF ?>" method = "POST"> Your Name Please: <input type = "text" name = "name" /> <br/>Your Age Please : <input type = "text" name = "age" /> <br/>Email Address : <input type = "email" name ="email"/> <br/><input type = "submit" />

  4. Discuss first line of the form <form action = "<?php $_PHP_SELF ?>" method = "POST"> The form tag requires two attributes: action and method. Action says to where the results will be sent to. You can include an url here or what I did, which will produce the current address. The results are stored in an Array with the name of $_POST[]; each element will have an identifier specified in the code. Method is either get or post. POST is used to send data to a server to create/update a resource. Get caches multiple get requests.

  5. The GET method produces a long string that appears in your server logs, in the browser's Location: box. The GET method is restricted to send upto 1024 characters only. Never use GET method if you have password or other sensitive information to be sent to the server. GET can't be used to send binary data, like images or word documents, to the server. The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method. The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING. The POST method does not have any restriction on data size to be sent. The POST method can be used to send ASCII as well as binary data. The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure. The PHP provides $_POST associative array to access all the sent information using POST method.

  6. Second line of the form Reading objects Your Name Please: <input type = "text" name = "name" /> The input tag and the attribute text will create a textBox for us. The name is the most important, that will become the identifier in the #_POST[name] array. There are different types we can use, text, submit, reset, textarea, email, etc.

  7. Retrieving data submitted Recall that the global array $_POST[] contains all data that was submitted. We can retrieve each data element by its name, for example $POST[age]; Let s echo just one element: echo $_POST['name']; <?php echo $_POST['name']; ?>

  8. Complete code <html> <head> </head> <body> <form action = "<?php $_PHP_SELF ?>" method = "POST"> Your Name Plase: <input type = "text" name = "name" /> <br/>Your Age Please : <input type = "text" name = "age" /> <br/>Email Address : <input type = "email" name ="email"/> <br/><input type = "submit" /> <?php //if (isset($_POST['submit])) { echo "<br/> <h1>You Entered: <br/></h1>"; echo ($_POST['name'] ); echo "<br/>"; echo $_POST['age']; echo "<br/>"; echo $_POST['email']; ?></form> </body> </html>

  9. Your Name Plase: Your Age Please : Email Address : You Entered: JOHN ABRAHAM 72 jpabraham@yahoo.com

More Related Content