简体   繁体   中英

how to set max value in quantity update in codeigniter cart

<?php echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], max=> $item['price'] ' type="number"  min="1" value="1" )'; ?>

如何设置最大值它显示我语法错误,意外的“=>”(T_DOUBLE_ARROW)

Easiest way is to pass associative array,

<?php 
      echo form_input(
             array(
               'name'=> 'cart[' . $item['id'] . '][qty]', 
               'type'=>"number",
               'min'=>1,
               'max'=> $item['price'],
               'value'=> $item['qty'], 
              ) 
      ); 
?>

You still can correct your existing one like below

<?php 
    echo form_input(
              /*name*/
             'cart[' . $item['id'] . '][qty]',  

             /* value */
             $item['qty'],                       

             /* other attributes as string */
             'max="'.$item['price'].'" type="number" min="1"'           
     ); 
?>

From :https://www.codeigniter.com/userguide3/helpers/form_helper.html

form_input([$data = ''[, $value = ''[, $extra = '']]])

Parameters:

 $data (array) – Field attributes data $value (string) – Field value $extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM