用php做一個(gè)簡(jiǎn)單的表單
Jun 21, 2016 am 09:14 AMPHP最有用的特性之一是它能夠自動(dòng)將表單中的變量值賦予PHP變量。這使得表單處理變得非常快捷。
因此,如果你送出一個(gè)內(nèi)含輸入欄位值的表單如下:
當(dāng)你用PHP處理此頁(yè)面,$name變量的值就會(huì)是 Glen Morris。
因此,你可以用如下的方式把值打印出來(lái):
echo "Hi $name!";
或者像這樣測(cè)試其值:
if ($name == "Glen Morris") { echo "Please check your email."; }
這有一個(gè)用PHP處理基本表單的很好方法。例如,我們需要做一個(gè)簡(jiǎn)單的問(wèn)卷調(diào)查,要求填寫者必須填寫他們的姓名,電子郵件地址,并回答一些我們感興趣的問(wèn)題。
首先,我們會(huì)將頁(yè)面拆成兩個(gè)函數(shù)。因此,我們只需要寫一個(gè) PHP頁(yè)面并用程序邏輯去控制對(duì)用戶的顯示內(nèi)容就可以了,而不是寫兩個(gè)單獨(dú)的網(wǎng)頁(yè)(一個(gè)針對(duì)表單部分,另外一個(gè)針對(duì)處理表單的CGI腳本)。
顯示表單
第一個(gè)函數(shù)用來(lái)顯示表單:
functiondisplay_form() {
global $PHP_SELF;
?>
}
?>
PHP最有用的特性之一是它能夠自動(dòng)將表單中的變量值賦予PHP變量。這使得表單處理變得非??旖荨?br>
因此,如果你送出一個(gè)內(nèi)含輸入欄位值的表單如下:
當(dāng)你用PHP處理此頁(yè)面,$name變量的值就會(huì)是 Glen Morris。
因此,你可以用如下的方式把值打印出來(lái):
echo "Hi $name!";
或者像這樣測(cè)試其值:
if ($name == "Glen Morris") { echo "Please check your email."; }
這有一個(gè)用PHP處理基本表單的很好方法。例如,我們需要做一個(gè)簡(jiǎn)單的問(wèn)卷調(diào)查,要求填寫者必須填寫他們的姓名,電子郵件地址,并回答一些我們感興趣的問(wèn)題。
首先,我們會(huì)將頁(yè)面拆成兩個(gè)函數(shù)。因此,我們只需要寫一個(gè) PHP頁(yè)面并用程序邏輯去控制對(duì)用戶的顯示內(nèi)容就可以了,而不是寫兩個(gè)單獨(dú)的網(wǎng)頁(yè)(一個(gè)針對(duì)表單部分,另外一個(gè)針對(duì)處理表單的CGI腳本)。
顯示表單
第一個(gè)函數(shù)用來(lái)顯示表單:
functiondisplay_form() {
global $PHP_SELF;
?>
}
?>
首先,如同我們處理$PHP_SELF一樣,我們獲取表單里面的全局變量。然后檢查cheese選項(xiàng)中哪一個(gè)被選中以按選擇創(chuàng)建回應(yīng)。
下面,我們使用count()函數(shù),以計(jì)算被選為喜好時(shí)段的時(shí)段數(shù)。在過(guò)去,必須通過(guò)檢查$cheese每一個(gè)可能的值來(lái)實(shí)現(xiàn),而現(xiàn)在我們只要利用大于、小于來(lái)比較$favorite_times的大小就可以了。如果你希望知道“$favorite_times > 1 && $favorite_times
在代碼最后,我們輸出用戶名以及我們提供給他的信息。當(dāng)然,你也可以實(shí)現(xiàn)各種各樣有趣的變化,例如,將信息存在數(shù)據(jù)庫(kù)中,或通過(guò)查詢數(shù)據(jù)庫(kù)中信息并以適當(dāng)格式返回結(jié)果。
組合表單
現(xiàn)在我們已得到此二函數(shù),接著只需要再放入一小段代碼,就可以把二者連接一起,并建立代碼所需的邏輯關(guān)系。在display_form() 以及process_form() 下加入以下代碼:
if (empty($stage)) { display_form(); }
else { process_form(); }
?>
首先,我們檢查變量$stage是否為空。在 PHP中,一個(gè)變量如果未曾初始化(即未曾賦值)或其值為零(也就是被賦值為零,即空白字串或者是零值),則該變量被視為空值。當(dāng)用戶首次訪問(wèn)網(wǎng)頁(yè)時(shí),$stage變量值為空。因此我們希望顯示表單;否則我們將處理表單內(nèi)容。
以上即如何使用PHP處理表單的過(guò)程。

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

The usage of the Type keyword in Go includes defining new type aliases or creating new structure types. Detailed introduction: 1. Type alias. Use the "type" keyword to create an alias for an existing type. This alias does not create a new type, but only provides a new name for the existing type. Type aliases can improve code. The readability of the code makes the code clearer; 2. Structure type. Use the "type" keyword to create a new structure type. The structure is a composite type that can be used to define custom types containing multiple fields. etc.

An error occurs when ubuntu mounts a mobile hard disk: mount: unknownfilesystemtype'exfat'. The processing method is as follows: Ubuntu13.10 or install exfat-fuse: sudoapt-getinstallexfat-fuseUbuntu13.04 or below sudoapt-add-repositoryppa:relan/exfatsudoapt-getupdatesudoapt-getinstallfuse- exfatCentOS Linux mount exfat format USB disk error solution to load extfa in CentOS

Preparation Use vuecreateexample to create a project. The parameters are roughly as follows: use native input. Native input is mainly value and change. The data needs to be synchronized when changing. App.tsx is as follows: import{ref}from'vue';exportdefault{setup(){//username is the data constusername=ref('Zhang San');//When the input box changes, synchronize the data constonInput=;return( )=>({

How to implement the laravel input hidden field: 1. Find and open the Blade template file; 2. Use the method_field method in the Blade template to create a hidden field. The creation syntax is "{{ method_field('DELETE') }}".

Solutions for clicking the input box without a cursor: 1. Confirm the focus of the input box; 2. Clear the browser cache; 3. Update the browser; 4. Use JavaScript; 5. Check the hardware device; 6. Check the input box properties; 7. Debug JavaScript code; 8. Check other elements of the page; 9. Consider browser compatibility.

php提交表單通過(guò)后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出php提交表單通過(guò)后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出而不是在空白頁(yè)彈出?想實(shí)現(xiàn)這樣的效果:而不是空白頁(yè)彈出:------解決方案--------------------如果你的驗(yàn)證用PHP在后端,那么就用Ajax;僅供參考:HTML code

Vue is a popular JavaScript front-end framework with a responsive data binding and component system at its core. In Vue applications, the input box is one of the most commonly used UI elements. When the user enters text, we hope to listen for the carriage return event and validate the input before submitting. This article will introduce the input box enter event and verification function usage in the Vue document. 1. The carriage return event of the input box in Vue. Monitoring the carriage return event of the input box in Vue is very simple.

Vue.js is a lightweight JavaScript framework that is easy to use, efficient and flexible. It is one of the most popular front-end frameworks currently. In Vue.js, input box binding events are a very common requirement. This article will introduce the input box binding events in the Vue document in detail. 1. Basic concepts In Vue.js, the input box binding event refers to binding the value of the input box to the data object of the Vue instance, thereby achieving two-way binding of input and response. In Vue.j
