2
<form action="next.php" method="post">
<table>
    <tr>
      <td>Paul</td>
      <td>Attuck</td>
      <td>[email protected]</td>
      <td><input type="checkbox" name="list[]" value="[email protected]" /></td>
    </tr>
    <tr>
      <td>James</td>
      <td>Bond</td>
      <td>[email protected]</td>
      <td><input type="checkbox" name="list[]" value="[email protected]" /></td>
    </tr>
    <tr>
      <td>Name</td>
      <td>Last</td>
      <td>[email protected]</td>
      <td><input type="checkbox" name="list[]" value="[email protected]" /></td>
    </tr>
</table>
    <input type="submit" name="submit" value="submit" />
</form>

and if i checked all checkbox and send form to next.php i can:

print_r($_POST['tags']);
// output
Array
(
    [0] => [email protected]
    [1] => [email protected]
    [2] => [email protected]
)

How can i make:

Array
    (
        [0] => array ([0] => Paul
                      [1] => Attuck
                      [2] => [email protected])
        [1] => array ([0] => James
                      [1] => Bond
                      [2] => [email protected])
        [2] => array ([0] => Last
                      [1] => Name
                      [2] => [email protected])
    )

? I try use serialize but this make " - dont can use this in html form.

1
  • 1
    There is really no way to achieve what you want. You'll have to use some workaround such as those posted by Rickesh and Eugen Commented Jan 24, 2012 at 13:55

3 Answers 3

5

If you make sure there is one character forbidden in the name fields (I use | here), you can do

<tr>
      <td>Paul</td>
      <td>Attuck</td>
      <td>[email protected]</td>
      <td><input type="checkbox" name="list[]" value="Paul|Attuck|[email protected]" /></td>
</tr>

And will get

print_r($_POST['tags']);
// output
Array
(
    [0] => Paul|Attuck|[email protected]
    [1] => James|Bond|[email protected]
    [2] => Last|Name|[email protected]
)

Which you can transform by

$names=array();
foreach ($_POST['tags']) as $tag)
  $names[]=explode('|',$tag,3);
Sign up to request clarification or add additional context in comments.

Comments

3

You have to give values like :

value="Paul,Attuck,[email protected]" 

And than explode it with , you will get your desire array.

Comments

1

The normal approach is to submit a value that can be used in subsequent database queries that will return the rest of the data. I suggest you consider that approach first.

If you really want to submit all fields, the simplest way is to separate them with a character that is not used in the fields and then split at the server, as others have commented.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.