Help: How does PHP get the value of the corresponding form by matching the partial string of the table sole name?

Source: Internet
Author: User
The problem may sound a bit around.
That's my form page. The individual number of tables is variable, because there is a button to increase the form, the user can press this button to increase the number of the table, and the name of the form I was to make it a "prefix + increment number" form, such as "Array_1", "array_2", but the exact number is uncertain, Because it depends on how many forms the user has added, I'm now going to put all the values of all the forms with array_ prefixes into an array, how do I do that? The key problem is that the number of non-forms is undefined.

Novice study, do not know to describe the problem clearly no, first thanked


Reply to discussion (solution)

Whether to increase the form or increase the form element

Do you have n forms in a page?

If there are multiple forms, I'm currently using jquery to dynamically get all the form values and then pass them to the background

var postdata= ""; $.each ($ ("from"), function (i, n) {    PostData + = $ (n). serialize ();}); /via AJAX to the backstage.

This post was last edited by xuzuning on 2013-12-28 16:32:56

There are multiple forms, only multiple form variables

foreach (Preg_grep ('/array_/', Array_keys ($_post)) as $k) {  res[$k] = $_post[$k];}

$res is the result you need.

In fact you are not named Array_ numbers, but named array[] don't need that much trouble.

There are multiple forms, only multiple form variables

foreach (Preg_grep ('/array_/', Array_keys ($_post)) as $k) {  res[$k] = $_post[$k];}

$res is the result you need.

In fact you are not named Array_ numbers, but named array[] don't need that much trouble.

Thanks, if the name is array[] how to do?

Whether to increase the form or increase the form element

Do you have n forms in a page?

If there are multiple forms, I'm currently using jquery to dynamically get all the form values and then pass them to the background

var postdata= ""; $.each ($ ("from"), function (i, n) {    PostData + = $ (n). serialize ();}); /via AJAX to the backstage.

Thanks, I have a problem with multiple form elements, that is, multiple input tags, not multiple forms

Multiple form input tags, which can be distinguished by the name attribute.

Define the name of the same group of elements as an array, as follows:


.........

PHP Reception is
Print_r ($_post[' array ');

Define the name of the same group of elements as an array, as follows:


.........

PHP Reception is
Print_r ($_post[' array ');

Originally can this, so convenient, teachable, thanks!




Print_r ($_post[' array ' [' A1 ']);
Print_r ($_post[' array ' [' A2 ']);

This allows you to differentiate the input value

There are multiple forms, only multiple form variables

foreach (Preg_grep ('/array_/', Array_keys ($_post)) as $k) {  res[$k] = $_post[$k];}

$res is the result you need.

In fact you are not named Array_ numbers, but named array[] don't need that much trouble.
jordan102 Moderator greatly answered my question, or thank you very much
  • 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.