PHP Knowledge

  • what is PHP

  • What is PHP class
  • Smarty PHP
  • PHP Calendar

  • PHP delete
  • PHP count

  • PHP Directory
  • php echo
  • php exec
  • PHP explode
  • PHP fopen

  • PHP Form
  • PHP get

  • PHP If
  • PHP list
  • php login
  • PHP LOOP
  • PHP Random
  • PHP Redirect
  • PHP replace
  • PHP session
  • PHP sort
  • PHP split
  • php substr
  • PHP Syntax
  • PHP time

  • PHP upload
  • php URL
  • PHP version
  • PHP Cookie
  • PHP Global
  • php LDAP
  • PHP list
  • php strip
  • PHP template
  • php PEAR
  • PHP md5
  • PHP ini
  • PHP FTP
  • More others

    Javascript
    CSS
    PHP

     

    PHP Form


    PHP Forms and User Input

    The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.

    PHP Form Handling

    The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

    Form example:

    <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html>

    The example HTML page above contains two input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the "welcome.php" file.

    The "welcome.php" file looks like this:

    <html>

    <body>

    Welcome

    <?php echo $_POST["name"]; ?>

    .<br />

    You are<?php echo $_POST["age"]; ?> years old.

    </body>

    </html>

    A sample output of the above script may be:

    Welcome John. You are 28 years old.

    The PHP $_GET and $_POST variables will be explained in the next chapters.

    Form Validation

    User input should be validated on the browser whenever possible (by client scripts (JavaScript)). Browser validation is faster and you reduce the server load.

    You should consider using server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Javascript |