I’ve managed to fix that, so that the form can POST correctly.
But it says that I keep leaving a field blank, even when it isn’t blank.
I can’t see anywhere in my code that would cause the dateofbirth form field not to be recognised.
PS. dateofbirth is a VARCHAR field in mysql, but it is a date input in the form. I don’t think that should be a problem.
<div class="row">
<?php echo $form->labelEx($model,'dateofbirth'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'dateofbirth',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
public function actionApply()
{
$model=new Users;
// $this->performAjaxValidation($model);
if(isset($_POST['Users']))
{
$model->attributes=$_POST['Users'];
if($model->save())
$this->redirect('site/apply');
}
$dataProvider=new CActiveDataProvider('Users');
$this->render('apply',array(
'dataProvider'=>$dataProvider,
'model'=>$model,
));
}
<?php
/**
* This is the model class for table "users".
*
* The followings are the available columns in table 'users':
* @property integer $id
* @property string $username
* @property string $password
* @property string $email
* @property integer $level
* @property string $firstname
* @property string $lastname
* @property string $firstline
* @property string $secondline
* @property string $city
* @property string $postcode
* @property string $phonenumber
* @property string $dateofbirth
* @property integer $upline
*/
class Users extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Users the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'users';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, email, firstname, lastname, firstline, secondline, city, postcode, phonenumber, dateofbirth', 'required'),
array('level, upline', 'numerical', 'integerOnly'=>true),
array('username, password, email, firstname, lastname, firstline, secondline, city, postcode, phonenumber, dateofbirth', 'length', 'max'=>255),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, username, password, email, level, firstname, lastname, firstline, secondline, city, postcode, phonenumber, dateofbirth, upline', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'username' => 'Username',
'password' => 'Password',
'email' => 'Email',
'level' => 'Level',
'firstname' => 'First Name',
'lastname' => 'Last Name',
'firstline' => 'Road name and number',
'secondline' => '2nd line of address',
'city' => 'City',
'postcode' => 'Postcode',
'phonenumber' => 'Phone number',
'dateofbirth' => 'Date of birth',
'upline' => 'Upline',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('username',$this->username,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('level',$this->level);
$criteria->compare('firstname',$this->firstname,true);
$criteria->compare('lastname',$this->lastname,true);
$criteria->compare('firstline',$this->firstline,true);
$criteria->compare('secondline',$this->secondline,true);
$criteria->compare('city',$this->city,true);
$criteria->compare('postcode',$this->postcode,true);
$criteria->compare('phonenumber',$this->phonenumber,true);
$criteria->compare('dateofbirth',$this->dateofbirth,true);
$criteria->compare('upline',$this->upline);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}