File tree Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace AppBundle \Controller ;
4
4
5
+ use AppBundle \Entity \Test ;
6
+ use AppBundle \Form \TestType ;
5
7
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
6
8
use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
7
9
use Symfony \Component \HttpFoundation \Request ;
@@ -13,9 +15,17 @@ class DefaultController extends Controller
13
15
*/
14
16
public function indexAction (Request $ request )
15
17
{
18
+ $ test = new Test ();
19
+ $ form = $ this ->createForm (TestType::class, $ test ,['csrf_protection ' =>false ]);
20
+ $ form ->submit (['url ' =>'http://symfony.com ' ]);
21
+ dump ($ form ->isSubmitted ());
22
+ dump ($ form ->isValid ());
23
+ dump ($ form ->getErrors (true ));
24
+
16
25
// replace this example code with whatever you need
17
26
return $ this ->render ('default/index.html.twig ' , [
18
27
'base_dir ' => realpath ($ this ->getParameter ('kernel.root_dir ' ).'/.. ' ).DIRECTORY_SEPARATOR ,
19
28
]);
29
+
20
30
}
21
31
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AppBundle \Entity ;
4
+
5
+ use Doctrine \ORM \Mapping as ORM ;
6
+ use Symfony \Component \Validator \Constraints as Assert ;
7
+
8
+
9
+ class Test {
10
+
11
+ private $ url ;
12
+
13
+ /**
14
+ * Set url
15
+ *
16
+ * @param string $url
17
+ *
18
+ * @return Test
19
+ */
20
+ public function setUrl ($ url ) {
21
+ $ this ->url = $ url ;
22
+
23
+ return $ this ;
24
+ }
25
+
26
+ /**
27
+ * Get url
28
+ *
29
+ * @return string
30
+ */
31
+ public function getUrl () {
32
+ return $ this ->url ;
33
+ }
34
+
35
+ /**
36
+ * @Assert\IsTrue()
37
+ */
38
+ public function isUrl () {
39
+ return true ;
40
+ }
41
+
42
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AppBundle \Form ;
4
+
5
+ use Symfony \Component \Form \AbstractType ;
6
+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
7
+ use Symfony \Component \Form \FormBuilderInterface ;
8
+ use Symfony \Component \OptionsResolver \OptionsResolver ;
9
+
10
+ class TestType extends AbstractType {
11
+
12
+ /**
13
+ * @param FormBuilderInterface $builder
14
+ * @param array $options
15
+ */
16
+ public function buildForm (FormBuilderInterface $ builder , array $ options ) {
17
+ $ builder
18
+ ->add ('url ' ,TextType::class)
19
+ ;
20
+ }
21
+
22
+ /**
23
+ * @param OptionsResolver $resolver
24
+ */
25
+ public function configureOptions (OptionsResolver $ resolver ) {
26
+ $ resolver ->setDefaults (array (
27
+ 'data_class ' => 'AppBundle\Entity\Test '
28
+ ));
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments