As soon as I came in, I saw two forms related issues. In fact, I am also directed at Forms related issues.

Source: Internet
Author: User
As soon as I saw two form problems, in fact, I am also directed at the form of the problem, there are the following table id ---- name ---- show1 ----- AA------12-----BB------04-----DD------033----FF------1 read the output after the operation of the table as soon as I saw two form problems, in fact, I am also directed at the form issue.
The following table is available:

Id ---- name ---- show
1-----AA------1
2-----BB------0
4-------dd------0
33----FF------1


The output operation form after reading is as follows:
AA
BB
DD
FF



Purpose: After submission, reset the show value of all fields in the table according to the check state. for example, if AA is not checked, set it to 0 after submission, and DD is checked, set it to 1 after submission
However, there is a problem here. The post-type array only contains the checked element. for example, the AA show is 1, and the output controller sets it as checked = "checked" by default during output ", that is, select the show option. in this case, I want to set the show option of AA to 0. so I disable the check option and select the DD that is not selected (I want to set the show option of DD to 1 ), submit the form. The Input type array is as follows:
Array
(
[0] => 4
[1] => 33
)

That is to say, only two checked elements are transmitted from the data. The first 0th elements are actually DD, and the second element is FF. the first AA and BB elements are not checked. after obtaining this array,
Set the record of the corresponding id to 1 based on the array value, but set it to 0 if no data is sent. how can this problem be solved?

====================
In another solution, the name value of the form is named by id instead of an array, that is, the following form (this is my stupid method, with the largest id value of the Hiden record added)
AA
BB
DD
FF


After submission, the selected items are submitted. I use the CI framework to do this ..
$ Maxid = get the largest id from the database;
$ Types = array ();
For ($ I = 1; $ I <= $ maxid; $ I ++ ){
$ Types [$ I] = ($ this-> input-> post ('type'. $ I) = false )? ;
// If it is not checked, for example, post ('type2') will return false, because the table quantity of type2 .. all input values are checked, so if it is not false, 1 is returned.
}

In this case, the for loop adds many non-existent interrupt ids. of course, the solution is to obtain the IDs of the existing IDs from the array.
Is there any other way? In the end, I actually want an array that describes the check status of all the options in the form. now I can only get the checked ones. if I do not select the ones, I will not pass the variables.

------ Solution --------------------
Only the selected checkbox can be submitted. The first option is reasonable.
------ Solution --------------------
You can concatenate the name values of all checkpoints into a string, for example, "type1, type2 ...... ", Upload it to the background. php splits it by using explode, and obtains the difference set between the obtained array and the received post key name.
------ Solution --------------------
In fact, the two methods are similar:

First: prepare an array in php, array (1, 2, 4, 33); traverse this array, check whether array [I] is in $ _ POST ['type']. you can use isset or in_array.

The second one is the same as the first one .. just concatenate strings .. array (1, 2, 4, 33), traverse this array, and check whether array [I] exists $ _ POST ['type '. $ array [I]

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.