0

I have a form like the one below which is posted to processForm.php, and the user can dynamically add more with jquery.

<input type="text" name="subject[]" />
<input type="text" name="grade[]" />
<input type="text" name="year[]" />

<input type="text" name="subject[]" />
<input type="text" name="grade[]" />
<input type="text" name="year[]" />

<input type="text" name="subject[]" />
<input type="text" name="grade[]" />
<input type="text" name="year[]" />

Please How can i access those arrays from subject[], grade[] and year[] inputs by the user?

Edited by Dani: Formatting fixed

3
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by erabxes
0

Hi, assuming the method is $_POST, you get the equivalent of:

$_POST['subject'][] = 'subject 1';
$_POST['subject'][] = 'subject 2';
$_POST['subject'][] = 'subject 3';
# and so on ...

so you can loop the values:

if(is_array($_POST['subject']))
{
    foreach($_POST['subject'] as $subject)
    {
        # code
    }
}

When debugging and in doubt, print the index:

echo '<pre>';
print_r($_POST['subject']);
echo '</pre'>;

So you can realize better how to handle the input. For more information check the documentation:

0

A big thanks to you, JorgeM. I think this works! I have tried it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.