View difference between Paste ID: cF62CEzu and
SHOW: | | - or go back to the newest paste.
1-
1+
<?php
2
3
// form to embed symfony autogenerated forms
4
5
class swThreadForm extends sfFormSymfony {
6
7
    public function configure() {
8
        $this->embedForm('thread', new ThreadForm());
9
    }
10
11
}
12
13
// thread form - autogenerated
14
15
class ThreadForm extends BaseThreadForm {
16
17
    public function configure() {
18
19
        $this->useFields(array(
20
            'body',
21
        ));
22
}
23
24
// base thread form - autogenerated
25
26
abstract class BaseThreadForm extends BaseFormDoctrine {
27
28
    public function setup() {
29
        $this->setWidgets(array(
30
            'id' => new sfWidgetFormInputHidden(),
31
            'body' => new sfWidgetFormTextarea(),
32
        ));
33
34
        $this->setValidators(array(
35
            'body' => new sfValidatorString(array('max_length' => 10000)),
36
        ));
37
38
        $this->validatorSchema->setPostValidator(
39
                new sfValidatorDoctrineUnique(array('model' => 'Thread', 'column' => array('id')))
40
        );
41
42
        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
43
44
        $this->setupInheritance();
45
46
        parent::setup();
47
    }
48
49
// the controller
50
51
    public function executeIndex(sfWebRequest $request) {
52
        $this->form = new swThreadForm();
53
    }
54
55
    public function executeCreate(sfWebRequest $request) {
56
        $this->form = new swThreadForm();
57
58
        if ($request->isMethod('post')) {
59
            $this->form->bind($request->getParameter('thread'));
60
            if ($this->form->isValid()) {
61
                $this->redirect('thread/welcome?' . http_build_query($this->form->getValues()));
62
            }
63
        }
64
65
        $this->setTemplate('index');
66
    }
67
68
// the index template
69
70
<form action="<?= url_for('thread/create') ?>" method="POST">
71
72
<?= $form['thread']['body']->renderLabel() ?>
73
<?= $form['thread']['body']->renderError() ?> // i always get REQUIRED no matter what i post
74
<?= $form['thread']['body']->render() ?>
75
76
<br /><br />
77
78
<input type="submit" value="Submit" />
79
80
</form>