Hướng dẫn dùng methods example trong PHP
Ngày đăng:
25/12/2022
Trả lời:
0
Lượt xem:
122
What is Form?When you login into a website or into your mail box, you are interacting with a form. Forms are used to get input from the user and submit it to the web server for processing. The diagram below illustrates the form handling process. A form is an HTML tag that contains graphical user interface items such as input box, check boxes radio buttons etc. The form is defined using the...tags and GUI items are defined using form elements such as input.When and why we are using forms?
Create a formWe will use HTML tags to create a form. Below is the minimal list of things you need to create a form.
Registration FormViewing the above code in a web browser displays the following form. HERE,
Submitting the form data to the serverThe action attribute of the form specifies the submission URL that processes the data. The method attribute specifies the submission type.PHP POST method
PHP GET method
GET vs POST MethodsPOSTGETValues not visible in the URLValues visible in the URLHas not limitation of the length of the values since they are submitted via the body of HTTPHas limitation on the length of the values usually 255 characters. This is because the values are displayed in the URL. Note the upper limit of the characters is dependent on the browser.Has lower performance compared to Php_GET method due to time spent encapsulation the Php_POST values in the HTTP bodyHas high performance compared to POST method dues to the simple nature of appending the values in the URL.Supports many different data types such as string, numeric, binary etc.Supports only string data types because the values are displayed in the URLResults cannot be book markedResults can be book marked due to the visibility of the values in the URLThe below diagram shows the difference between get and postProcessing the registration form dataThe registration form submits data to itself as specified in the action attribute of the form. When a form has been submitted, the values are populated in the $_POST super global array. We will use the PHP isset function to check if the form values have been filled in the $_POST array and process the data. We will modify the registration form to include the PHP code that processes the data. Below is the modified codeRegistration Form //this code is executed when the form is submittedHERE,
More examplesSimple search engineWe will design a simple search engine that uses the PHP_GET method as the form submission type. For simplicity’s sake, we will use a PHP If statement to determine the output. We will use the same HTML code for the registration form above and make minimal modifications to it.Simple Search EngineView the above page in a web browser The following form will be shown Type GET in upper case letter then click on submit button. The following will be shown The diagram below shows the URL for the above results Note the URL has displayed the value of search_term and form_submitted. Try to enter anything different from GET then click on submit button and see what results you will get. Working with check boxes, radio buttonsIf the user does not select a check box or radio button, no value is submitted, if the user selects a check box or radio button, the value one (1) or true is submitted. We will modify the registration form code and include a check button that allows the user to agree to the terms of service.Registration FormView the above form in a browser Fill in the first and last names Note the Agree to Terms of Service checkbox has not been selected. Click on submit button You will get the following results Click on back to the form link and then select the checkbox Click on submit button You will get the following results Summary
|