This is the view file:
<h1>Information Request Form</h1>
<?php
// Flash message
if(Yii::app()->user->hasFlash('contact')):
?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('contact'); ?>
</div>
<?php else: ?>
<?php
$this->beginWidget('CMarkdown', array('purifyOutput'=>true));
echo $labels['intro']['siteitem'];
$this->endWidget();
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm'); ?>
<p class="note"><?php echo $labels['required']['siteitem']; ?></p>
<?php echo $form->errorSummary($model); ?>
<fieldset>
<legend>Your data:</legend>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'phone'); ?>
<?php echo $form->textField($model,'phone'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address', array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'city'); ?>
<?php echo $form->textField($model,'city', array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'state'); ?>
<?php echo $form->textField($model,'state', array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'zip'); ?>
<?php echo $form->textField($model,'zip', array('size'=>10,'maxlength'=>20)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'dealer'); ?>
<?php echo $form->dropDownList($dealers, 'id', CHtml::listData($dealers->active()->findAll(),'id','area'), array('prompt'=>'Choose your country:')); ?>
</div>
</fieldset>
<fieldset>
<legend>Your question:</legend>
<div class="row">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'body'); ?>
<?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>
</div>
</fieldset>
<?php if(extension_loaded('gd')): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint"><?php echo $labels['hint']['siteitem']; ?></div>
</div>
<?php endif; ?>
<div class="row submit">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<?php endif; ?>
…and this is the model:
<?php
/**
* ContactForm class.
* ContactForm is the data structure for keeping
* contact form data. It is used by the 'contact' action of 'SiteController'.
*/
class ContactForm extends CFormModel
{
public $name;
public $email;
public $phone;
public $address;
public $city;
public $state;
public $zip;
public $dealer;
public $subject;
public $body;
public $verifyCode;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, dealer, phone, subject, body', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
array('dealer','safe'),
);
}
/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
'state'=>'State / Province / Region',
'zip'=>'Zip Code',
'dealer'=>'Country',
);
}
}
Very very simple as you can see. But it doesn’t work correctly.
Mauro