模态对话框jquery规则

Dear all

I'm a newbie in PHP, jQuery and bad in English.

I want to ask about jQuery modal dialog rules, from database. This is my database:

Database picture

This is my code: Javascript rules and jQuery Validate without the load of the database:

rules: {
  user: {
    required: true,
    number: true,
    range: [1, 8]
  }                        
},
messages: {
user: {
required: "* sorry field user empty.",
number: "* Field user must number.",
    range: "* Field user must between 1 to 8"
}                     
}

I used PHP and this is my form field, from the user only.

<?php $user = array(
          'name'           => 'user',
          'id'             => 'user',
          'class'          => 'user',
          'value'          => '',
          'style'          => 'border: groove 2px;',
          'size'           => '3',
          'maxlength'      => '3'
          ); ?>
          <td> <?php echo form_label('User');?> </td>
        <td> : </td>
        <td> <?php echo form_input($user); ?></td>

The question is how to input rules with load a database.

For example:

If I login with userdata and load the database the $items value is 8.

echo $this->session->userdata('items')

Are the range rules automatically between 1 to 8? Like the following image:

My modal dialog

And, if the login userdata to load database $items value is 6, are the range rules automatically between 1 to 6? The same question if $items is 4.

I need your help.

Thank you so much for your attention.

Best regards,

Puja

I am not sure what form_input() does but you can try adding variable to input and extract it when attaching validation rules

$user = array(
      'name'           => 'user',
      'id'             => 'user',
      'class'          => 'user',
      'value'          => '',
      'style'          => 'border: groove 2px;',
      'size'           => '3',
      'maxlength'      => '3',
      'data-range'     => $this->session->userdata('items')
      );

And in javascript code

rules: {
  user: {
      required: true,
      number: true,
      range: [1, parseInt($('#user').data('range'))]
}...    

If data will not be added to the generated input field you can try add this to class, for example

 'class'          => 'user range_'.$this->session->userdata('items'),

and in js change

parseInt($('#user').attr('class'))

to

parseInt($('#user').attr('class').substring($('#user').attr('class').indexOf('range_')+6));   //add 6 as this is the length of range_