-1

I'm looking for the documentation of Array in checkbox name

<input type="checkbox" name="array[]" value="value1">
<input type="checkbox" name="array[]" value="value2">
<input type="checkbox" name="array[]" value="value3">

in a form using method post

<form action="script.php" method="post">...</form>

I wanted to know how it is work.

Thanks!

  • Do you want to have multiple checkboxes with the same array? Also please provide us with the "script.php" – Kayelder Apr 25 '17 at 11:16
  • Also, For the one who downvoted the question. Everyone has been a beginner, hell even I am a beginner in programming in general. Just help people with the questions they have so we can all learn from eachother – Kayelder Apr 25 '17 at 11:18
  • http://php.net/manual/en/faq.html.php#faq.html.arrays – CBroe Apr 25 '17 at 11:20
  • Yes, I forgot to specify that there are multiple checkbox. Actually, I needed a documentation of the "sending" of these data through post method. My code works, I didn't understand the binding between "array[]" name and what stays into $_POST. I'm sorry if the answer is a poorly-phrased question. –  Apr 25 '17 at 12:03
  • The "script.php" simply shows the value of the checkboxes. –  Apr 25 '17 at 12:05

1 Answers1

1

As yes. A similar question has been answered. a.k.a

PHP Multiple Checkbox Array

<form method='post' id='userform' action='thisform.php'> <tr>
<td>Trouble Type</td>
<td>
<input type='checkbox' name='checkboxvar[]' value='Option One'>1<br>
<input type='checkbox' name='checkboxvar[]' value='Option Two'>2<br>
<input type='checkbox' name='checkboxvar[]' value='Option Three'>3
</td> </tr> </table> <input type='submit' class='buttons'> </form>

You pass the form name as an array and then you can access all checked boxes using the var itself which would then be an array.

<?php if (isset($_POST['checkboxvar'])) {
print_r($_POST['checkboxvar']); } ?>

Also, what @CBroe has posted. Please read the documentation before diving in something. Good luck!

Community
  • 1
  • 1
Kayelder
  • 155
  • 1
  • 2
  • 18
  • Thank for the answer. I checked the question you linked before to make this, but I didn't find the answer I was looking for. Maybe I composed the question bad but, I wanted to know what happens when the data into the form have sent to the php script. –  Apr 25 '17 at 11:54
  • If you did it correctly, the values you have put in your form will be posted to the php file you entered. Inside that php file you can pass on the data to the database, or do something else with it – Kayelder Apr 25 '17 at 11:55
  • If you want to know what happens to the data when you send it using the form you should check out this example on w3schools. It shows a small example of this https://www.w3schools.com/php/showphp.asp?filename=demo_form_validation_complete – Kayelder Apr 25 '17 at 11:58
  • Judging from the question, you are a beginner at this. Don't worry we all start somewhere. Just keep going, keep trying and you will eventually get there – Kayelder Apr 25 '17 at 12:01
  • Really thank you for the help and patience! Like I just wrote above, my code works. It was a simply test to verify the functioning of Array string as name of checkboxes (I really don't know how to say it differently). –  Apr 25 '17 at 12:12
  • Welp, I'm glad you resolved it. I would appreciate a check to the answer to let the rest know your question has been resolved c; Happy Coding! – Kayelder Apr 25 '17 at 12:13