How Can I Submit an Array from an HTML Form Without JavaScript?

Patricia Arquette
Release: 2024-11-21 14:14:11
Original
795 people have browsed it

How Can I Submit an Array from an HTML Form Without JavaScript?

POST an Array from an HTML Form Without JavaScript

This question proposes a challenge of sending an array of tuples from a complex HTML form to simplify server-side processing. The form includes two sections: one for user information and another for a list of trees. The goal is to avoid using JavaScript and support a wider user base.

The solution presented in the answers involves structuring the form inputs as follows:

<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="text" name="email">
<input type="text" name="address">

<input type="text" name="tree[tree1][fruit]">
<input type="text" name="tree[tree1][height]">

<input type="text" name="tree[tree2][fruit]">
<input type="text" name="tree[tree2][height]">

<input type="text" name="tree[tree3][fruit]">
<input type="text" name="tree[tree3][height]">
Copy after login

This structure results in the following $_POST array in PHP format:

$_POST[] = array(
    'firstname' => 'value',
    'lastname' => 'value',
    'email' => 'value',
    'address' => 'value',
    'tree' => array(
        'tree1' => array(
            'fruit' => 'value',
            'height' => 'value'
        ),
        'tree2' => array(
            'fruit' => 'value',
            'height' => 'value'
        ),
        'tree3' => array(
            'fruit' => 'value',
            'height' => 'value'
        )
    )
)
Copy after login

By following this approach, the server can access the user and tree data as an array of arrays, facilitating efficient processing without the need for JavaScript.

The above is the detailed content of How Can I Submit an Array from an HTML Form Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template