PHP dynamic input box to get the input value

Source: Internet
Author: User
Simulates the public account background voting management function. You can add multiple questions dynamically. Each question has two options by default. You can also add multiple questions dynamically. The dynamic addition function has been implemented through JS, but the value of the problem option cannot be obtained in PHP. The html of a single option is as follows {code...} Because every...

Simulates the public account background voting management function.
You can add multiple questions dynamically. Each question has two options by default. You can also add multiple questions dynamically. The dynamic addition function has been implemented through JS, but the value of the problem option cannot be obtained in PHP. The html of a single option is as follows:

*

Because there are options for each problem, ifname="options[]"In this way, you cannot know which problem the option belongs.

How can I set it correctly?inputElementnameAttribute.

Reply content:

Simulates the public account background voting management function.
You can add multiple questions dynamically. Each question has two options by default. You can also add multiple questions dynamically. The dynamic addition function has been implemented through JS, but the value of the problem option cannot be obtained in PHP. The html of a single option is as follows:

*

Because there are options for each problem, ifname="options[]"In this way, you cannot know which problem the option belongs.

How can I set it correctly?inputElementnameAttribute.

There are too many open-source codes to solve this problem. The basic idea is to count the number of existing inputs before adding them, then count + 1 sets the array name = "options [" + count + "]" for name.

Paste several existing open source codes

Http://jsfiddle.net/jaredwilli/tzpg4/4/

Http://bootsnipp.com/snippets/featured/dynamic-form-fields-add-amp-remove

Question 1 name = "question [0]" option name = "answer [0] [0]" name = "answer [0] [1]" question 2 name = "question [1] "option name =" answer [1] [0] "name =" answer [1] [1]"

By adding a hidden field to store the problem label, the code of the dynamic output problem segment is solved. However, this is only the addition phase, and later modifications may be more troublesome. Thank you.

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.