Form handling is one of the common tasks when creating the project in
PHP. There are various methods are available for this and they are good
according to the situation.
You can either pass the form data by URL and hidden them from the user.
Contents
1. $_GET
- Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL).
- $_GET also has limits on the amount of information to send. The limitation is about 2000 characters.
- However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.
- $_GET may be used for sending non-sensitive data.
<?php if(isset($_GET['submit'])){ $name = $_GET['name']; $email = $_GET['email']; $age = $_GET['age']; echo "name : ".$name."<br>"; echo "email : ".$email."<br>"; echo "age : ".$age; } ?> <form method='get' action=''> Name : <input type='text' name='name' /> <br/> Email : <input type='text' name='email' /> <br/> Age : <input type='text' name='age' /> <br/> <input type='submit' value='Submit' name='submit'> </form>
2. $_POST
- Information sent from a form with the POST method is invisible to other and has no limits on the amount of information to send.
- Moreover, $_POST support advanced functionality such as support for multipart binary input while uploading files to server.
- However, because the variables are not displayed in the URL, it is not possible to bookmark the page.
<?php if(isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $age = $_POST['age']; echo "name : ".$name."<br>"; echo "email : ".$email."<br>"; echo "age : ".$age; } ?> <form method='post' action=''> Name : <input type='text' name='name' /> <br/> Email : <input type='text' name='email' /> <br/> Age : <input type='text' name='age' /> <br/> <input type='submit' value='Submit' name='submit'> </form>
3. $_REQUEST
- This method is work as GET method if it is use in <form method=” >.
- It contains the contents of $_GET, $_POST, and $_COOKIE.
<?php if(isset($_REQUEST['submit'])){ $name = $_REQUEST['name']; $email = $_REQUEST['email']; $age = $_REQUEST['age']; echo "name : ".$name."<br>"; echo "email : ".$email."<br>"; echo "age : ".$age; } ?> <form method='request' action=''> Name : <input type='text' name='name' /> <br/> Email : <input type='text' name='email' /> <br/> Age : <input type='text' name='age' /> <br/> <input type='submit' value='Submit' name='submit'> </form>
0 Comments:
Post a Comment