Detailed explanation of PHP forms
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible
