Jump to content

jQuery - Sending "Select All" Check boxes with Multiple Forms


PrestashopEnthu

Recommended Posts

I have checked online for a solution to pass my values for the checkbox **`"select all"`**. I have multiple forms in a page. So I will need to separate passing the values based on specific forms.

jQuery:

$(document).ready(function() {
$(".select-all").change(function () {
  $(this).siblings().prop('checked', $(this).prop("checked"));
  });
})

HTML for form:

<div class="col">
  <fieldset>
    <form action="{$link->getLink('controller')|escape:'htmlall':'utf-8'}" method="post"> 
      <p>
        {foreach from=$payment item=row}
        <input type="checkbox" name="payment[]" maxlength="50" value={$row.id_order}>
        <label> ID: <b>{$row.id_order}</b></label><br/>
        {/foreach}
        <br/>
        <input id="submit" name="submitpayment" type="submit" value="PACK ITEMS" class="button" />
      </p>
    </form>
  </fieldset>
</div>

**`Error (Value is empty):`**

input type="checkbox" class="select-all" name="payment[]" value=""

SQL query to pass records:

public function displayOrdersbyID()
{
$query1 = new DbQuery();
$query1->select('o.id_order')
->from('orders','o')
->leftJoin('carrier','c','o.id_carrier=c.id_carrier')
->leftJoin('order_state_lang','s','o.current_state=s.id_order_state')
->where('c.name = ' . "'XXX'")
->where('s.name = ' . "'Payment accepted'");
$payment = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query1);
$this->context->smarty->assign( 'payment', $payment);

Controller:

if (Tools::isSubmit('submitpayment')) { 
$ids= Tools::getValue('payment');

$query18 = new DbQuery();
$query18->select('id_order_state')
->from('order_state_lang')
->where('name = ' . "'Processing in progress'");
$updateinprogress = Db::getInstance()->getValue($query18);

foreach ($ids as $updateids) {
$objOrder = new Order($updateids);
$history = new OrderHistory();
$history->id_order = (int)$objOrder->id;
$history->id_employee = $cookie->id_employee;
$history->changeIdOrderState($updateinprogress, (int)($objOrder->id));
$history->add(true);
$history->save();
}
}

SELECT ALL checkbox:

<input type="checkbox" class="select-all" name="payment[]" value=
       {$row.id_order}> 
<label> SELECT ALL</label>

I was using the above code to create a SELECT ALL checkbox for the form, placing it outside the loop. I understand it is wrong and value is not passing, where should I place the checkbox at? If no records are passed, it will return the following error: 

Property OrderHistory->id_order_state is empty at line 909 in file classes/ObjectModel.php

Any guidance is appreciated.

Thank you.

Edited by Enthu86 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...