insert batch with group checkbox |
Hi. I have a group of checkbox like this:
Code: <input type="checkbox" name="preview[]" value="1"/> and the follow code in my controller: PHP Code: for($i = 0; $i < $count; $i++) The value of checkbox is wrong. This is or always 1 or always 0. I have tried too the ternary operator, something like this: PHP Code: $c = $this->request->getPost('preview') == 1 ? 1 : 0; but the problem has not been resolved. Someone can help me please? Thanks ![]()
I'm not really getting on what you're trying to achieve. Makes no sense to me that the checkbox value is always the same.
Maybe if you provide the entire form HTML for more context and explain what you're really trying to do we could help you better.
Website: marcomonteiro.net | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
(07-02-2020, 06:41 AM)marcogmonteiro Wrote: I'm not really getting on what you're trying to achieve. Makes no sense to me that the checkbox value is always the same. Hi Marco, thanks for help me. I would like use the checkbox for select the preview images. The preview images should have a value 1 the others 0. ![]()
(07-02-2020, 07:19 AM)eleumas Wrote:(07-02-2020, 06:41 AM)marcogmonteiro Wrote: I'm not really getting on what you're trying to achieve. Makes no sense to me that the checkbox value is always the same. Why don't you pass Product id to checkbox instead 1 for all (07-02-2020, 11:26 AM)DarkKnight Wrote:(07-02-2020, 07:19 AM)eleumas Wrote:(07-02-2020, 06:41 AM)marcogmonteiro Wrote: I'm not really getting on what you're trying to achieve. Makes no sense to me that the checkbox value is always the same. Ok i can pass the product id but the problem is the same. what change if i pass product id? please, can you explain better. Thanks.
Your code assumes a checkbox that is not selected will still submit a value.. that's never going to work. I'm also not sure that nested loops are necessary here?
Your field names should be something like: Code: Row 1: images[0][title], images[0][alt], images[0][text] and images[0][preview] Then you would do like this: PHP Code: $images = []];
If you have this:
PHP Code: <input type="checkbox" name="preview[]" value="<?= $product->id ?>"/> then in your controller you would do PHP Code: foreach($this->request->getPost('preview) as $key => $product_id {
Website: marcomonteiro.net | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
|
Welcome Guest, Not a member yet? Register Sign In |