Form traditional values
table of Contents
Receiving data in three ways PHP
Receiving data in the form of box
Common data processing check box
concept
Forms pass by value, ie browser form elements to the user's selection or input of the data submitted to the backend server language.
Why use a form by value
Features dynamic website (web2.0) is the back-end customized data according to user needs, the so-called "demand" is the user through the current selection or enter data information, the form is the bearer of these data.
Forms pass by value
GET traditional values
1) form form
<Form method = "GET"> form element </ form>
2) a label
<a href=”www.itcast.cn/index.php?学科=php”>
href attribute 3) location of the object
<script>location.href =”www.itcast.cn/index.php?data=php”</script>
assign () method 4) location of the object - to load a new document
<script>location.assign( ”www.itcast.cn/index.php?data=php”)</script>
POST pass value
Basic setting 1) post the form of embodiment
<Form method = "POST"> form element </ form>
2) post get way with the difference between the way
1, data transfer is mainly used to get access to data, without changing the server resources: get just to get content, does not change the content on the server data
2, post data transmission is mainly used to increase the data changes on the server resource: post will change the content on the server data
. 3, POST form must form the transmission. And get forms and can use the form URL
4, get data transfer can begin to be seen in the URL and post ,, invisible: GET traditional values will eventually show all the address bar of your browser:? Data name = data value = 2 & data name data value 2 ...
5, get and post data can be transmitted in different size, get to 2k, post theory unlimited. (In fact, GET and POST data itself is no length limit, but the browser manufacturers make some restrictions)
6, GET and POST data format that can be transmitted are different: get simple data transmission (number or string), post can submit complex data (binary, etc.)
Receiving data in three ways PHP
Whether $ _GET / $ _ POST / $ _ REQUEST, three are PHP superglobals (no range limits) a predefined array, the form element " name value" attribute as a subscript of the array, and the value corresponding to the attribute value is an array element values.
$ _GET ways: receiving data submitted by the GET method
$ _POST ways: receiving data submitted by the POST method
$ _REQUEST way: all data is received POST or GET submitted
1) $ _ content data stored REQUEST: $ _GET and $ _POST will merge into a memory array
2) $ _ REQUEST and $ _POST and $ _GET Contact: If you have the same name as the array element (index) GET and POST in, POST overwrites GET (PHP in the array element index is unique), this may in php.ini configuration.
GET / POST / REQUEST relations
Demonstrated in the REQUEST POST overwrites GET
PHP data processing check box
Check box form item naming
Checkboxes: usually a class of contents to the same background (the same name) in the form of a database is usually stored in a storage field. Box features: Select will be submitted.
1, in the browser, the value of the name attribute checkbox whatever will be submitted without reservations browser.
2, in PHP, $ _ POST / $ _ GET will be covered by the name attribute of the same name.
Solution: The browser does not recognize [] (browsers do not think there particularity), but PHP think [] particularity: the system automatically considered the symbol is an array, so PHP will automatically with the same name but with [ ] combinations of elements together to form an array.
Receiving data in the form of box
PHP will automatically be combined into an array of elements of the same name.
Common data processing check box
1) Data processing radio button
radio button: you can have multiple options, but only a select
1, name attribute used in the form, you can use the same name: You can only select a
2, background data does not need to receive additional treatment
3, database storage, if desired, only to a field for storing normal data (numeric or string)
4. After PHP to get the data, organizations SQL data tables can be stored directly to the
Data Processing 2) of checkboxes
1, the form name attribute using an array format: Name [] (a class of data using a check box)
2, after receipt of the data is a background array, the array can not be stored directly in the database.
3, PHP need to convert the array into a string in a specified format, delimiters and dividing each element of the string is formed:
implode (array, 'separator');
4, PHP tissue SQL stored directly in the database
Data taken out box
1, taken after the data string into an array using explode
2, among the HTML display, by determining whether the checkbox elements present in the array to determine whether there CheckBox checkbox checked = "checked" property: in_array ();
3) Other conventional data processing with individual watches
In addition to radio button radio buttons and check boxes CheckBox, rarely watches the same item, if you must use the same name to be managed, it can be used CheckBox way to operate.
1, the form increases the same name []
2, the receiving array processing PHP
3, PHP converted into a string of formatted
4, character string storage database
Box details
如果复选框没有选中,那么浏览器就不会提交。因此在PHP接收使用复选框(单选框)的数据的时候,应该先判断是否存在该数据。