Re: How to handle rows of checkboxes upon form submit?
| From: | Casey | Date: | Fri, 07 Dec 2007 06:35:28 +0000 |
| Subject: | Re: How to handle rows of checkboxes upon form submit? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265545@lists.php.net to get a copy of this message | ||
On Dec 6, 2007 10:25 PM, Casey <heavyccasey@gmail.com> wrote:
>
> On Dec 6, 2007 10:12 PM, Rob Gould <gouldimg@mac.com> wrote:
> > Let's say I have a PHP script which lists a series of objects for sale at a yard
> > sale, each with a checkbox to the left of the name of the item.
> >
> > If I wanted to have a submit button, and run through the list of items that were checked
> > and act on them, how would I do that?
> >
> > To gain some knowledge, I went into phpMyAdmin and looked at their checkboxes, and I see
> > their code:
> >
> > <input type="checkbox" id="checkbox_row_6" value="apples"
> > name="selected_fld[]">
> > <input type="checkbox" id="checkbox_row_7"
> > value="oranges" name="selected_fld[]">
> > <input type="checkbox" id="checkbox_row_8"
> > value="bananas" name="selected_fld[]">
> >
> >
> > So it looks like they do something with name="select_fld[]", which must be part
> > of the secret to making this work.
> >
> > Any advice is greatly appreciated.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> Use this code:
> <?php if (empty($_POST) { ?>
> <form action="" method="post">
> <input type="checkbox" id="checkbox_row_6" value="apples"
> name="selected_fld[]" />
> <input type="checkbox" id="checkbox_row_7" value="oranges"
> name="selected_fld[]" />
> <input type="checkbox" id="checkbox_row_8" value="bananas"
> name="selected_fld[]" />
> <button type="submit">Submit<button>
> </form>
> <?php
> } else echo '<pre>', print_r($_POST, true), '</pre>';
> ?>
>
> This will print out the postdata, along with the "secrets" to how this works.
>
> -Casey
>
Sorry, parse error :]
<?php if (empty($_POST)) { ?>
<form action="" method="post">
<input type="checkbox" id="checkbox_row_6" value="apples"
name="selected_fld[]" />
<input type="checkbox" id="checkbox_row_7" value="oranges"
name="selected_fld[]" />
<input type="checkbox" id="checkbox_row_8" value="bananas"
name="selected_fld[]" />
<button type="submit">Submit<button>
</form>
<?php
} else echo '<pre>', print_r($_POST, true), '</pre>';
?>
This basically says what Stephen said.
-Casey