Commit 69b2b372 by Qiang Xue

form wip

parent 74246a23
...@@ -18,6 +18,7 @@ class LoginForm extends Model ...@@ -18,6 +18,7 @@ class LoginForm extends Model
{ {
public $username; public $username;
public $password; public $password;
public $rememberMe = true;
public function rules() public function rules()
{ {
...@@ -25,6 +26,7 @@ class LoginForm extends Model ...@@ -25,6 +26,7 @@ class LoginForm extends Model
array('username', 'required'), array('username', 'required'),
array('password', 'required'), array('password', 'required'),
array('password', 'validatePassword'), array('password', 'validatePassword'),
array('rememberMe', 'boolean'),
); );
} }
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
*/ */
use yii\helpers\Html; use yii\helpers\Html;
?> ?>
<?php $this->beginPage(); ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<?php $this->beginPage(); ?>
<head> <head>
<meta charset="utf-8" />
<title><?php echo Html::encode($this->title); ?></title> <title><?php echo Html::encode($this->title); ?></title>
<?php $this->head(); ?> <?php $this->head(); ?>
</head> </head>
...@@ -18,5 +19,5 @@ use yii\helpers\Html; ...@@ -18,5 +19,5 @@ use yii\helpers\Html;
<?php echo $content; ?> <?php echo $content; ?>
<?php $this->endBody(); ?> <?php $this->endBody(); ?>
</body> </body>
<?php $this->endPage(); ?>
</html> </html>
<?php $this->endPage(); ?>
\ No newline at end of file
...@@ -14,13 +14,6 @@ use yii\helpers\Html; ...@@ -14,13 +14,6 @@ use yii\helpers\Html;
<?php $form = $this->beginWidget('yii\widgets\ActiveForm'); ?> <?php $form = $this->beginWidget('yii\widgets\ActiveForm'); ?>
<?php echo $form->field($model, 'username')->textInput(); ?> <?php echo $form->field($model, 'username')->textInput(); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php <?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
$field = $form->field($model, 'username');
echo $field->begin() . "\n"
. $field->label() . "\n"
. Html::activeTextInput($model, 'username') . "\n"
. $field->error() . "\n"
. $field->end();
?>
<?php echo Html::submitButton('Login'); ?> <?php echo Html::submitButton('Login'); ?>
<?php $this->endWidget(); ?> <?php $this->endWidget(); ?>
\ No newline at end of file
...@@ -771,7 +771,7 @@ class Html ...@@ -771,7 +771,7 @@ class Html
* @param array $items the data item used to generate the checkboxes. * @param array $items the data item used to generate the checkboxes.
* The array keys are the labels, while the array values are the corresponding checkbox values. * The array keys are the labels, while the array values are the corresponding checkbox values.
* Note that the labels will NOT be HTML-encoded, while the values will. * Note that the labels will NOT be HTML-encoded, while the values will.
* @param array $options options (name => config) for the checkbox list. The following options are specially handled: * @param array $options options (name => config) for the checkbox list. The following options are supported:
* *
* - unselect: string, the value that should be submitted when none of the checkboxes is selected. * - unselect: string, the value that should be submitted when none of the checkboxes is selected.
* By setting this option, a hidden input will be generated. * By setting this option, a hidden input will be generated.
...@@ -785,7 +785,7 @@ class Html ...@@ -785,7 +785,7 @@ class Html
* *
* where $index is the zero-based index of the checkbox in the whole list; $label * where $index is the zero-based index of the checkbox in the whole list; $label
* is the label for the checkbox; and $name, $value and $checked represent the name, * is the label for the checkbox; and $name, $value and $checked represent the name,
* value and the checked status of the checkbox input. * value and the checked status of the checkbox input, respectively.
* @return string the generated checkbox list * @return string the generated checkbox list
*/ */
public static function checkboxList($name, $selection = null, $items = array(), $options = array()) public static function checkboxList($name, $selection = null, $items = array(), $options = array())
...@@ -829,7 +829,7 @@ class Html ...@@ -829,7 +829,7 @@ class Html
* @param array $items the data item used to generate the radio buttons. * @param array $items the data item used to generate the radio buttons.
* The array keys are the labels, while the array values are the corresponding radio button values. * The array keys are the labels, while the array values are the corresponding radio button values.
* Note that the labels will NOT be HTML-encoded, while the values will. * Note that the labels will NOT be HTML-encoded, while the values will.
* @param array $options options (name => config) for the radio button list. The following options are specially handled: * @param array $options options (name => config) for the radio button list. The following options are supported:
* *
* - unselect: string, the value that should be submitted when none of the radio buttons is selected. * - unselect: string, the value that should be submitted when none of the radio buttons is selected.
* By setting this option, a hidden input will be generated. * By setting this option, a hidden input will be generated.
...@@ -843,7 +843,7 @@ class Html ...@@ -843,7 +843,7 @@ class Html
* *
* where $index is the zero-based index of the radio button in the whole list; $label * where $index is the zero-based index of the radio button in the whole list; $label
* is the label for the radio button; and $name, $value and $checked represent the name, * is the label for the radio button; and $name, $value and $checked represent the name,
* value and the checked status of the radio button input. * value and the checked status of the radio button input, respectively.
* @return string the generated radio button list * @return string the generated radio button list
*/ */
public static function radioList($name, $selection = null, $items = array(), $options = array()) public static function radioList($name, $selection = null, $items = array(), $options = array())
...@@ -885,8 +885,9 @@ class Html ...@@ -885,8 +885,9 @@ class Html
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* The following options are specially handled: * The following options are specially handled:
* *
* - label: this specifies the label to be displayed. If this is not set, [[Model::getAttributeLabel()]] * - label: this specifies the label to be displayed. Note that this will NOT be [[encoded()]].
* will be called to get the label for display. Note that this will NOT be [[encoded()]]. * If this is not set, [[Model::getAttributeLabel()]] will be called to get the label for display
* (after encoding).
* *
* @return string the generated label tag * @return string the generated label tag
*/ */
......
...@@ -70,8 +70,8 @@ class BooleanValidator extends Validator ...@@ -70,8 +70,8 @@ class BooleanValidator extends Validator
*/ */
public function validateValue($value) public function validateValue($value)
{ {
return $this->strict && ($value == $this->trueValue || $value == $this->falseValue) return !$this->strict && ($value == $this->trueValue || $value == $this->falseValue)
|| !$this->strict && ($value === $this->trueValue || $value === $this->falseValue); || $this->strict && ($value === $this->trueValue || $value === $this->falseValue);
} }
/** /**
......
...@@ -30,6 +30,11 @@ class ActiveForm extends Widget ...@@ -30,6 +30,11 @@ class ActiveForm extends Widget
* Defaults to 'post'. * Defaults to 'post'.
*/ */
public $method = 'post'; public $method = 'post';
/**
* @param array $options the attributes (name-value pairs) for the form tag.
* The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
*/
public $options = array(); public $options = array();
/** /**
* @var string the default CSS class for the error summary container. * @var string the default CSS class for the error summary container.
...@@ -37,12 +42,14 @@ class ActiveForm extends Widget ...@@ -37,12 +42,14 @@ class ActiveForm extends Widget
*/ */
public $errorSummaryCssClass = 'yii-error-summary'; public $errorSummaryCssClass = 'yii-error-summary';
/** /**
* @var boolean whether to enable client-side data validation. Defaults to false. * @var boolean whether to enable client-side data validation.
* When this property is set true, client-side validation will be performed by validators * Client-side validation will be performed by validators that support it
* that support it (see {@link CValidator::enableClientValidation} and {@link CValidator::clientValidateAttribute}). * (see [[\yii\validators\Validator::enableClientValidation]] and [[\yii\validators\Validator::clientValidateAttribute()]]).
*/
public $enableClientValidation = true;
/**
* @var array the default configuration used by [[field()]] when creating a new field object.
*/ */
public $enableClientValidation = false;
public $fieldConfig = array( public $fieldConfig = array(
'class' => 'yii\widgets\ActiveField', 'class' => 'yii\widgets\ActiveField',
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment