Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace frontend\models;
- use Yii;
- use yii\base\Model;
- use common\models\Contactmaster;
- use yii\base\Exception;
- use yii\helpers\ArrayHelper;
- /**
- * ContactForm is the model behind the contact form.
- */
- class ContactForm extends Model
- {
- public $name;
- public $verifyCode;
- public $phone;
- public $specialnosty_id;
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- // name, email, subject and body are required
- [['name', 'phone'], 'required'],
- [['specialnosty_id'], 'integer'],
- [['name', 'phone'], 'string', 'max' => 50],
- // email has to be a valid email address
- // verifyCode needs to be entered correctly
- ['verifyCode', 'captcha'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'verifyCode' => 'Введите код с картинки',
- 'name' => 'Ваше имя',
- 'phone' => 'Ваш номер телефона',
- 'specialnosty_id' => 'Специальность',
- ];
- }
- public function getModel()
- {
- if (!$this->model) {
- $this->model = new Contactmaster();
- }
- return $this->model;
- }
- public function setModel($model)
- {
- $this->name = $model->name;
- $this->phone = $model->phone;
- $this->model = $model;
- return $this->model;
- }/**
- * Sends an email to the specified email address using the information collected by this model.
- *
- * @param string $email the target email address
- * @return bool whether the email was sent
- */
- public function save()
- {
- if ($this->validate()) {
- $model = $this->getModel();
- $isNewRecord = $model->getIsNewRecord();
- $model->name = $this->name;
- $model->phone = $this->phone;
- if (!$model->save()) {
- throw new Exception('Model not saved');
- }
- }
- return $model;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment