Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // form to embed symfony autogenerated forms
- class swThreadForm extends sfFormSymfony {
- public function configure() {
- $this->embedForm('thread', new ThreadForm());
- }
- }
- // thread form - autogenerated
- class ThreadForm extends BaseThreadForm {
- public function configure() {
- $this->useFields(array(
- 'body',
- ));
- }
- // base thread form - autogenerated
- abstract class BaseThreadForm extends BaseFormDoctrine {
- public function setup() {
- $this->setWidgets(array(
- 'id' => new sfWidgetFormInputHidden(),
- 'body' => new sfWidgetFormTextarea(),
- ));
- $this->setValidators(array(
- 'body' => new sfValidatorString(array('max_length' => 10000)),
- ));
- $this->validatorSchema->setPostValidator(
- new sfValidatorDoctrineUnique(array('model' => 'Thread', 'column' => array('id')))
- );
- $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
- $this->setupInheritance();
- parent::setup();
- }
- // the controller
- public function executeIndex(sfWebRequest $request) {
- $this->form = new swThreadForm();
- }
- public function executeCreate(sfWebRequest $request) {
- $this->form = new swThreadForm();
- if ($request->isMethod('post')) {
- $this->form->bind($request->getParameter('thread'));
- if ($this->form->isValid()) {
- $this->redirect('thread/welcome?' . http_build_query($this->form->getValues()));
- }
- }
- $this->setTemplate('index');
- }
- // the index template
- <form action="<?= url_for('thread/create') ?>" method="POST">
- <?= $form['thread']['body']->renderLabel() ?>
- <?= $form['thread']['body']->renderError() ?> // i always get REQUIRED no matter what i post
- <?= $form['thread']['body']->render() ?>
- <br /><br />
- <input type="submit" value="Submit" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement