Just tried out the new CForm for my registration form, but I had no luck. No error summary in case of an input error, no insert into the db (if no error was made). Nothing, only the form with the fields populated with the data I entered before submitting.
In my case the registration form is split up into 2 subforms because
-
One Account can have
-
multiple Email addresses
I have an Account model and an Email model.
My form configuration (protected/views/site/subscribeForm):
return array(
'showErrorSummary' => true,
'title' => Yii::t('subscribe', 'Get a free account'),
'method' => 'post',
'elements' => array(
'Email' => array(
'type' => 'form',
'model' => new Email,
'elements' => array(
'email_type_id' => array(
'type' => 'dropdownlist',
'items' => CHtml::listData(EmailType::model()->active()->findAll(),
'id', 'nameLocalized'),
),
'email' => array(
'type' => 'text',
),
),
),
'Account' => array(
'type' => 'form',
'model' => new Account,
'elements' => array(
'gender_id' => array(
'type' => 'dropdownlist',
'items' => CHtml::listData(Gender::model()->findAll(), 'id',
'nameLocalized'),
'label' => '',
),
),
),
),
'buttons' => array(
'submit' => array(
'type' => 'submit',
'label' => Yii::t('form', 'Subscribe'),
),
),
);
The controller
...
public function actionSubscribe()
{
$form = new CForm('application.views.site.subscribeForm');
if ($form->submitted() && $form->validate()) {
$account = $form['Account']->model;
$email = $form['Email']->model;
if ($account->save(false)) {
$email->id = $account->id;
$email->save(false);
$this->redirect(array('thankyou'));
}
}
$this->render('subscribe', array('form'=>$form));
}
...
The view protected/views/site/subscribe.php
$this->pageTitle=Yii::t('headlines', 'Subscribe');
$this->breadcrumbs=array($this->pageTitle);
?>
<h1><?php echo CHtml::encode($this->pageTitle); ?></h1>
<?php echo $form; ?>
Maybe you can point out, what I did wrong?
Thank you!