phpmonger
(Rcjsanders)
February 20, 2015, 12:28pm
1
Hello I’m building a forum application with yii2 and I’m encountering a strange problem with the ActiveForm::begin()
$form = ActiveForm::begin(['action' => 'forum-post/create', 'id' => 'forum_post', 'method' => 'post',]);
Doesn’t work as described in the Yii2 guide.
I have a model ForumPost,
I have the controller ForumPostController
I have the directory forum-post.
The ActiveForm is rendered within the index page in form-post/index.php to send the formdata which is rendered from _form.php, I have to send it to the controller action create. This doesn’t work because the action attribute in the renderd html-form is not processed, it stays ‘forum-post/create’.
<form id="forum_post" class="form-vertical" action="forum-post/create" method="post">
In short the route is not processed. I guess this is an error in the framework??
phtamas
(Phtamas)
February 20, 2015, 12:48pm
2
Documentation is missing but Yii conventions suggest that action should be an array to indicate that it isn’t an URL but a route:
$form = ActiveForm::begin(['action' =>['forum-post/create'], 'id' => 'forum_post', 'method' => 'post',]);
phpmonger
(Rcjsanders)
February 20, 2015, 12:56pm
3
phtamas:
Documentation is missing but Yii conventions suggest that action should be an array to indicate that it isn’t an URL but a route:
$form = ActiveForm::begin(['action' =>['forum-post/create'], 'id' => 'forum_post', 'method' => 'post',]);
Hello phtamas, thx for your reply, I encountered this same issue with the arrays on several places in yii2. It did the trick, many thx buddy.
It now converts to the route.
<form id="forum_post" class="form-vertical" action="/project/frontend/web/index.php?r=forum-post%2Fcreate" method="post">