Pages

Wednesday, April 13, 2011

Adding a extra field in formWidgets

Class files invloved
1. TblNameForm.class.php

//Adding an extra field ---here we are adding a text field

Inside the configure function inside TblNameForm.class.php add a field
$this->widgetSchema('extraField',new sfFormInputText(array('label'=>'My Extra Field')));

Now add a validation for the extra field
$this->setValidator('extraField',new sfValidatorString(array('max_length'=>255')
));

Int the BaseTblNameForm.class.php add

$this->validatorSchema->setOption('allow_extra_fields', true);

Thats it we have added a extra field, Last and final thing to do is drawing the field in the template

your templateSuccess.php

<?php
echo $form['extraField']->renderLabel();
echo $form['extraField']->render();
?>

Thats it we have sucessfully added an extra field.

No comments:

Post a Comment