Keep form textfield input on invalid submission

Hello everyone, sorry for what is probably a simple question, but I want my form textfields to remember input on invalid submission. For example, in the following form I want the ‘emails’ textfield not to erase any data the user has entered if the required ‘name’ field has been left blank and a submission is attempted.

Would this sort of validation require AJAX or Javascript?

I am extending CFormModel.

I don’t believe there to be any relevant code in the controller, so I left it out.

Here’s the widget in the view:

<?php $form=$this->beginWidget('CActiveForm', array(








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

<div class="row">

  <?php echo $form->error($model,'name'); ?>

  <?php echo $form->labelEx($model,'name (required)'); ?>

  <?php echo $form->textField($model,'name'); ?>


// takes in comma separated emails

<label for="emails">Emails:</label>

<input type="text" name="emails">

<div class="row buttons">

  <?php echo CHtml::submitButton('Create'); ?>


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

Here’s the relevant model code:

class ThisForm extends CFormModel


 public function rules()


  return array(

  // project name is required

  array('name', 'required'),




Was it something I said?

On the contrary, we need to see controller’s action.

I figured it out. It did indeed relate to my controller.

Relavant controller snippet:




      "emails"=> isset($_POST['emails']) ? $_POST['emails'] : '',


And here’s the updated view snippet:

<input type="text" name="emails" value='<?php echo CHtml::encode($emails); ?>'>