All pastes #2072701 Raw Edit

Mine

public text v1 · immutable
#2072701 ·published 2011-05-31 09:46 UTC
rendered paste body
# protected/models/RequestForm.php
<?php

class RequestForm extends CFormModel {

    public $organization;
    public $name;
    public $email;
    public $telefon;
    public $text;
    public $verifyCode;
    
    public function rules()
    {
        return array(
            array('name, telefon, text, verifyCode', 'required'),
            array('verifyCode', 'captcha', 'allowEmpty' => !extension_loaded('gd'), 'captchaAction' => 'site/captcha')
        );
    }

    public function attributeLabels()
    {
        return array(
            'organization'=>'Организация',
            'name'=>'Контактное лицо',
            'email'=>'Email',
            'telefon'=>'Телефон',
            'text'=>'Текст заявки',
            'verifyCode'=>'Введите символы с картинки',
        );
    }
    
    public function action() {
        $reqForm = new RequestForm;
        if(isset($_POST['RequestForm'])) {
            $reqForm->attributes = $_POST['RequestForm'];
            $reqForm->organiztion = $_POST['RequestForm']['organiztion'];
            $reqForm->name = $_POST['RequestForm']['name'];
            $reqForm->email = $_POST['RequestForm']['email'];
            $reqForm->telefon = $_POST['RequestForm']['telefon'];
            $reqForm->text = $_POST['RequestForm']['text'];
            $email = Yii::app()->email;
            $email->to = 'МЫЛО';
            $email->subject = 'Заявка';
            $email->message = 'Организация: ' . $reqForm->organization . '
            Контактное лицо: ' . $reqForm->name . '
            Email: ' . $reqForm->email . '
            Телефон: ' . $reqForm->telefon . '
            Текст заявки: ' . '
            ' . $reqForm->text;
            $email->send();
            if($model->validate()) $this->redirect(Yii::app()->user->returnUrl);
        }
        $this->redirect('/submitted');
    }
}

# protected/views/layouts/column2.php
<div class="form">
    <?php $reqform = new RequestForm;?>
    <?php $form = $this->beginWidget('CActiveForm', array(
        'enableAjaxValidation'=>true,
        'id'=>'RequestForm',
    )); ?>
     
        <?php echo $form->errorSummary($reqform); ?>
     <table>
        <div class="row"><tr>
            <td><?php echo $form->label($reqform,'organization', array('class'=>'formlabel',)); ?></td>
            <td><?php echo $form->textField($reqform,'organization') ?></td>
        </tr></div>
     
        <div class="row"><tr>
            <td><?php echo $form->label($reqform,'name', array('class'=>'formlabel',)); ?></td>
            <td><?php echo $form->textField($reqform,'name') ?></td>
        </tr></div>
     
        <div class="row"><tr>
            <td><?php echo $form->label($reqform,'email', array('class'=>'formlabel',)); ?></td>
            <td><?php echo $form->textField($reqform,'email') ?></td>
        </tr></div>
     
        <div class="row"><tr>
            <td><?php echo $form->label($reqform,'telefon', array('class'=>'formlabel',)); ?></td>
            <td><?php echo $form->textField($reqform,'telefon') ?></td>
        </tr></div>                            
     </table>
        <div class="row">
            <?php echo $form->label($reqform,'text', array('class'=>'formlabel')); ?>
            <?php echo $form->textArea($reqform,'text', array('class'=>'area_type1')) ?>
        </div>
        <?php if (extension_loaded('gd')) { ?>
            <div class="row">
                <?php echo $form->labelEx($reqform, 'verifyCode', array('class'=>'formlabel'));?>
                <div>
                    <?php $this->widget('CCaptcha', array('captchaAction' => 'site/captcha'));?>
                    <?php echo $form->textField($reqform, 'verifyCode');?>
                </div>
                <?php echo $form->error($reqform, 'verifyCode');?>
            </div>
        <?php } ?>                         
        <div class="row submit">
            <?php echo CHtml::submitButton('Отправить'); ?>
        </div>                         
    <?php $this->endWidget(); ?>
</div><!-- form -->