title: Yii2:Saving listbox multi-select field to db
body: <p>I am created a listbox and related functions like in my model Appointment.php</p>
  
  <p><strong>Validation Rule &amp; related function in Appointment.php</strong></p>
  
  <pre><code>public function rules()
      {
          return [            
              ['weekdays', 'validateWeekDays'],
  
          ];
      }
  
  public static function getWeekdaysList()
          {
              return [
                  'monday' =&gt; 'Monday',
                  'tuesday' =&gt; 'Tuesday',
                  'wednesday' =&gt; 'Wednesday',
                  'thursday' =&gt; 'Thursday',
                  'friday' =&gt; 'Friday',
                  'saturday' =&gt; 'Saturday',
                  'sunday' =&gt; 'Sunday',
              ];
          }
      public function validateWeekdays ($attribute, $params)
          {
              $label = '«' . $this-&gt;getAttributeLabel($attribute) . '»';
  
              // Checking if it's array first
              if (is_array(!$this-&gt;$attribute)) {    
                  $this-&gt;addError($attribute, "$label must be array.");
  
                  return;
              }
  
              $allowedWeekdays = array_keys(static::getWeekdayslist());
  
              // Checking if every selection is in list of allowed values
              foreach ($this-&gt;$attribute as $weekday) 
              {
                  if (!in_array($weekday, $allowedWeekdays)) {
                      $this-&gt;addError($attribute, "$label - $weekday is not in allowed list");
                  }
              }
  </code></pre>
  
  <p><strong>Then in my _form.php</strong></p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'weekdays')-&gt;listBox(app\models\Appointment::getWeekdaysList(), [
      'multiple' =&gt; true,
      'size' =&gt; 7,
  ]) ?&gt; 
  </code></pre>
  
  <p>Now while saving the form I am getting the error like:
  <strong>Database Exception – yii\db\Exception</strong></p>
  
  <pre><code>PDOStatement::bindValue() expects parameter 3 to be long, string given
  Failed to prepare SQL: INSERT INTO `appointment` (`appointment_id`,
  `appointment_date`, 
   `patient_detail_id`, `patient_name`, 
  `priority`, `doctor_name`, `doctor_fee`, 
  `discount`, `weekdays`, `total_amount`, 
  `is_paid`, `hospital_commission`) VALUES 
  (:qp0, :qp1, :qp2, :qp3, :qp4, :qp5, 
  :qp6, :qp7, :qp8, :qp9, :qp10, :qp11)
  </code></pre>
  
  <p>What I need to do to correct this error. Thanks.</p>