activeHiddenField doesn't render

Hello,

I followed best practise - do server changes only with POST rq. So, I’m deleting a record. User click on <a href> link, which points to Controller/action, that renders confirmation form. Form with two buttons:

  • "No" - regular <a href> link, which points back to listing of records

  • "Yes" - submit button of Form. action attribute of Form points to Controller/action which deletes record from Model

I want to transport ID of deleting record in hidden form field. But for some "magic" reason, this field is not rendering into HTML code. So my ID is not present in final Controller/action which deletes record from Model.

Some code:

models/Cornfimator.php




class Cornfimator extends CFormModel

{

	public $id;


	public function rules()

	{

		return array(

			array('id', 'required'),

			array('id', 'safe'),

			array('id', 'numerical', 'integerOnly'=>true)

		);

	}

}



Controller




public function actionDelete()

{

	if (!isset($_GET['id'])) {

		$this->redirect('listing');

	} else {

		$model = new Cornfimator();

		$model->id = intval($_GET['id']);

		$this->render('delete', array('model'=>$model));

	}

}


public function actionDeleteConfirmed()

{

	CVarDumper::dump($_POST, 4, true);echo '<br>';

	die;

}



views/<CONTROLLER>/delete.php




<?php echo CHtml::beginForm('deleteConfirmed'); ?>

	<?php CHtml::activeHiddenField($model, 'id'); ?>

	<a href="<?php echo $this->createUrl('listing'); ?>">No</a>

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

<?php echo CHtml::endForm(); ?>



HTML code




<form method="post" action="/deleteConfirmed">

	<a href="/admin/ratings">No</a>

	<input type="submit" value="Yes" name="yt0">

</form>



As you can see, hidden field is not present in HTML code. I don’t know why is this field ignored during rendering.

PLS help. THX.

Arrrgh, lost an hour of time for dumb error in View template:


<?php CHtml::activeHiddenField($model, 'id'); ?>

It is missing an echo command.

Please close topic.