When it comes to Web development, we have to mention HTML, which has been the de facto standard for Web user interface design for several years. Although the current use of page scripts such as WAP/XML makes it difficult to maintain the dominance of HTML, if you want to write front-end PHP web applications, developers still need to understand the HTML language, especially the form part of HTML. In this chapter, we will learn the following: ? Use Dreamweaver to design HTML forms ? Use PHP to send and receive form data ? PHP form multi-page value transfer and processing ? Use PHP to verify user input ? Prevent in PHP Some lightweight attacks ? Two session management methods of PHP: COOKIE and SESSION ? Planning our web applications 5.1 Forms and HTML HTML is a simple markup language that provides users with great Flexibility, which makes it easy to learn and write. It is also because of this that too many web designers almost abuse the design and coding of HTML, causing a page to run in several different browsers such as IE, Firefox, and Mozila. shown to be very different. Today’s web design has enabled new standards, aiming to make the HTML of web pages only contain content and information, and store information in standard HTML and CSS (cascading style sheets), which is the now popular DIV+CSS design standard. Some people suggest using XML to replace HTML language. Although XML has such powerful functions, the entry barrier is high and daunting, and there are currently too many HTML-based websites. Therefore, the current standard is the compatible specification of HTML and XML, called XHTML, which is used to Transition from HTML to XML. The code in this book is based on XHTML compatibility, and it is recommended that you also apply XHTML to Web projects. Creating and processing forms is an important competency indicator for PHP developers. Next we start to introduce how to design the form. Forms are the most commonly used components in web applications, consisting of submit buttons and other related elements. Forms are used in various fields to implement functions such as registering users, filling in bank accounts, and logging in. The form uses as the start tag and ends with , otherwise it will have no effect. Several forms are allowed in an HTML page, and the name and Form ID of the form are used as the distinction between them when writing. The following is the simplest form, the code is as follows:
This form will only display a button on the browser "Submit query content" "The words don't have much meaning. If you want to submit data and form a complete form, you need to add two important attribute tags to the tag: action and method, as shown in the following form:
where the action tag refers to the file location that receives the processing result. When the action value is empty, it is submitted to the current file itself. If the action value is other file or URL, then submit it to the file or URL address for processing. The method tag describes the method used when submitting data. It has two values: GET and POST. If the method attribute is not set or the attribute is empty, the browser defaults to the POST method. Here’s how to handle POST forms. Example 5-1: getPasswd.php – Accept values submitted by POST form $action = $_SERVER['PHP_SELF']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo 'Use POST method to pass form values'; echo "$_POST[email]"; } ?>
If you want to send a form or data to the server in the browser, you can use the GET or POST method. The GET method uses the browser address bar to pass the value when accessing the URL. We can see this kind of URL string on many websites. What is shown in Figure 5-1 is to use the GET method to pass parameters.
Error-prone, and the length of the string passed by GET cannot exceed 250 characters If the characters are too long, the browser will automatically truncate them, resulting in data loss. In addition, the GET method does not support any characters other than ASCII characters. For example, when it contains Chinese characters or other non-ASCII characters, additional encoding operations are required, although sometimes the browser can automatically complete it (you can use the url_encode and url_decode functions, use See section 2.9.2 for details on the method). When the POST method sends variable data, it is opaque to the user. According to the HTTP protocol, the data is attached to the header information of the header and the user cannot modify it at will. This is much safer for web applications. And using POST, you can send large volumes of data to the web server. Because POST is sent together with the HTTP header information, when the POST form submission is triggered, if the user clicks the "Back" button while browsing the page, the browser will not automatically resend the POST data. If the user clicks the "Refresh" button at this time, there will be a prompt "The data has expired, do you want to resubmit the form?" This is not as convenient as GET. When using GET to pass values, even if the user uses the "Back" or "Refresh" button, the browser's URL address still exists. Therefore, we need to flexibly choose GET and POST to submit form data according to the actual application during development. It is worth mentioning that if the form closing tag is missing in HTML, then the entire form will not trigger any submission action. During actual development, some careless people will find that nothing happens when clicking the button. In fact, just check the form code carefully. Sometimes even if one HTML character is missing, the browser will not do the work for us. 5.4 Form Elements There are more than a dozen tag elements used in forms. The commonly used and important tags in PHP development are shown in Table 5-1. Table 5-1 Form element description input type="checkbox" checkbox, allowing users to select multiple options input type="file" file browsing box, which can be used to open a modal window when a file is uploaded To select a file input type="hidden" hidden label, used to implicitly submit variable values in the form input type="password" Password text box, when the user enters characters in the text box, it will be replaced and displayed as * No. input type="radio" single option, used to set a set of options, the user can only select one input type="reset" to clear and reset the content of the form, used to clear the content of all text boxes in the form, and Restore the selection menu items to their initial values input type="submit" form submission button input type="text" single-line text box select drop-down list box, which can be single-selected or multi-selected. The default is single selection. If you want to add multiple selection function, add
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.
PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.
PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.
PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.
PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.
PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.