Forms and Form Elements

t-visualappeal edited this page Feb 22, 2012 · 1 revision

Forms demo

The behavior of the CActiveForm and the EBootstrapActiveForm are nearly the same. At the moment it is not a good idea to perform ajax- or clientvalidation. I will fix this as soon as possible. The main difference is that you have to wrap the elements via $form->beginControlGroup($model, $attribute)and $form->endControlGroup(). The input and error via $form->beginControls() and $form->endControls(). That is important so that the error messages look nice.

<?php $form=$this->beginWidget('EBootstrapActiveForm', array(
    'id'=>'contact-form',
    'horizontal' => true,
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <?php echo $form->beginControlGroup($model, 'name'); ?>
        <?php echo $form->labelEx($model,'name'); ?>
        <?php echo $form->beginControls(); ?>
            <?php echo $form->textField($model,'name'); ?>
            <?php echo $form->error($model,'name'); ?>
        <?php echo $form->endControls(); ?>
    <?php echo $form->endControlGroup(); ?>

    <?php echo $form->beginControlGroup($model, 'email'); ?>
        <?php echo $form->labelEx($model,'email'); ?>
        <?php echo $form->beginControls(); ?>
            <?php echo $form->textFieldPrepend($model,'email','@'); ?>
            <?php echo $form->error($model,'email'); ?>
        <?php echo $form->endControls(); ?>
    <?php echo $form->endControlGroup(); ?>

    <?php echo $form->beginControlGroup($model, 'subject'); ?>
        <?php echo $form->labelEx($model,'subject'); ?>
        <?php echo $form->beginControls(); ?>
            <?php echo $form->textFieldAppend($model,'subject','!',array('maxlength'=>128)); ?>
            <?php echo $form->error($model,'subject'); ?>
        <?php echo $form->endControls(); ?>
    <?php echo $form->endControlGroup(); ?>

    <?php echo $form->beginControlGroup($model, 'body'); ?>
        <?php echo $form->labelEx($model,'body'); ?>
        <?php echo $form->beginControls(); ?>
            <?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>
            <?php echo $form->error($model,'body'); ?>
        <?php echo $form->endControls(); ?>
    <?php echo $form->endControlGroup(); ?>

    <?php if(CCaptcha::checkRequirements()): ?>
        <div class="captcha">
            <?php echo $form->beginControlGroup($model, 'body'); ?>
                <?php echo $form->labelEx($model,'verifyCode'); ?>
                <?php echo $form->beginControls(); ?>
                    <?php $this->widget('CCaptcha'); ?><br />
                    <?php echo $form->textField($model,'verifyCode'); ?>

                    <?php echo $form->helpBlock('Please enter the letters as they are shown in the image above.<br />Letters are not case-sensitive.'); ?>
                    <?php echo $form->error($model,'verifyCode'); ?>
                <?php echo $form->endControls(); ?>
            <?php echo $form->endControls(); ?>
        </div>
    <?php endif; ?>

    <?php echo $form->beginActions(); ?>
        <?php echo $form->submitButton('Submit'); ?>
    <?php echo $form->endActions(); ?>

<?php $this->endWidget(); ?>

Buttons

The form buttons (i.e. submit) has to be wrapped into $form->beginActions() and $form->endActions().

Per default the submit button will be a primary button. In the future there will be the possibility to remove this class.

Help Block

You can help the user with a help block below the input

$form->helpBlock('Please enter the letters as they are shown in the image above.<br />Letters are not case-sensitive.')

Search field

EBootstrap::searchField($name, $value = '', $htmlOptions = array());