Using forms in PHP

Source: Internet
Author: User
?? Summary: Forms, as a key way for users to submit information, have always been the most basic aspect of PHP programming and a major key and difficulty for entry personnel. How do we select the number of processing associations and get the checkbox with the same name ?? Summary:Form, as a key way for users to submit information, has always been the most basic aspect of PHP programming, and it is also a big key and difficult point for entry. We select a location that is confusing when dealing with the number of associations, obtaining the checkbox of the same name, and uploading files.

?? How to apply form transfer to join arrays?

?? The associated array passed through the form can be read by the each () function. The program is as follows:

// Test1.php
<Form action = 'test2. php' method = post>
<Input type = hidden name = 'Var [Address] 'value = 'Beijing'>
<Input type = hidden name = 'Var ['age'] 'value = '20'>
<Input type = submit value = submit>
After the element named var [Address] with the value of 'Beijing' is submitted to test2.php, it becomes an associated array. var ['address'] = 'Beijing ':
// Test2.php
<?
Echo $ var ['address'];
?>
?? Output result: Beijing

?? How to handle checkbox with the same name?

?? Code:

Test1.php:
<Form method = post action = 'test2. php'>
Apple <input type = 'checkbox' NAME = 'Come [] 'value = 'apple'> <BR>
Pear <input type = 'checkbox' NAME = 'Come [] 'value = 'pyary'> <BR>
Banana <input type = 'checkbox' NAME = 'Come [] 'value = 'banana '> <BR>
Watermelon <input type = 'checkbox' NAME = 'Come [] 'value = 'watermelon '> <BR>
<Input type = 'submit 'VALUE = 'submit'>
</FORM>

Test2.php:
Your choice: <BR>
<?
For ($ I = 0; $ I <sizeof ($ come); $ I) echo $ come [$ I], '<BR> ';
?> ?? In this way, the "come []" element submitted from test1.php forms an array, so that we can easily process it.

?? How can we observe all submitted information?

?? In general, the PHP engine places each form field in an array called $ HTTP_POST_VARS, so we can read this array to observe all submitted information:

<?
?? Echo 'post value: <BR> ';
?? While (list ($ key, $ val) = each ($ HTTP_POST_VARS )){
??? Echo '$ key => $ val <BR> ';
??}
?>
?? How to upload multiple files at the same time?

?? Let's look at an example.

?? The following is the submission page for uploading files. using this page, you can not only Upload 1000 file frames (or any number of 0 ~ N), and the retention paths can be distinguished.

?? The file input box on the submit page is named: file0, file1,... file100,... fileN
?? The file path box on the submit page is named path0, path1,... path100,... pathN.
?? Because the page is inherently very simple, it is not described here. two functions are defined using javascript. check () is used to submit the page, and create () is used to upload a natural file.
???? Phpfileup.htm
???? --------------------------------------------------------
???? Example file php9.txt]
???? --------------------------------------------------------
?? The following task is quite clear when the file submission page is created: Keep the submitted file content on the server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.