1

我正在尝试从使用 CActiveForm 小部件创建的表单中检索数据。但是,当我单击提交按钮时,没有数据写入目标 URL。如何获取提交的表单数据?

<p>Please list the ages of the members of your household:</p>

<div class="form offset3">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'survey',
        'enableClientValidation' => true,
        'enableAjaxValidation' => true,
        'action'=>Yii::app()->createUrl('//survey_resp'),
        'clientOptions' => array(
        'validateOnSubmit' => true,
        ),
        'htmlOptions' => array(
        'class' => 'form-horizontal',
        ),
));
?>

    <div class="row">
        <?php echo $form->labelEx($model, 'age_1'); ?>
        <?php echo $form->textField($model, 'age_1'); ?>
        <?php echo $form->error($model, 'age_1'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'age_2'); ?>
        <?php echo $form->textField($model, 'age_2'); ?>
        <?php echo $form->error($model, 'age_2'); ?>
    </div>

    <div class="row rememberMe">
        <?php echo $form->checkBox($model, 'resp_re'); ?>
        <?php echo $form->Label($model, 'resp_re'); ?>
        <?php echo $form->error($model, 'resp_re'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('submit'); ?>
    </div>

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

1 回答 1

2

“survey_resp”是您的控制器还是您的操作?如果它是一个动作,那么你应该为表单的动作输入正确的 url。例子:

 'action'=>Yii::app()->createUrl('/you_controller_name/your_action_name'),

ps:记住,如果你把“//”放在createUrl中,它会生成一个指向basePath或模块的url。见http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detailhttp://www.yiiframework.com/doc/api/1.1/CActiveForm#action-detail

于 2013-08-23T19:27:04.093 回答