logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Module and action not in request when submitting a form

Hello,

I have quite a strange problem with a Symfony 1.4 project that I haven't been able to solve after doing lots of research and debugging. I think it is something small that I am missing cause I did stuff like this a million times before without a problem. I have a page called storySingle, this page has a form where users can leave a comment.
// storySingleSuccess.php
<form action="<?php echo url_for('@user_story?title='.$story->getSlug()) ?>" method="post">
<?php echo $form ?>
<input type="submit" value='Reactie plaatsen'/>
</form>


The form will submit to itself and saving the form information is handled in the action:
<?php
class profileActions extends sfActions
{

[.....]

public function executeStorySingle(sfWebRequest $request)
{
$title = $request->getParameter('title');
$this->name = $request->getParameter('subdomain');

$this->user = Doctrine::getTable('sfGuardUser')->retrieveByUsername($this->name);
$this->story = Doctrine::getTable('Story')->retrieveByUserIdAndSlug($this->user->getId(), $title);

$options = array(
'story_id' => $this->story->getId(),
);
$this->form = new StoryCommentForm(null, $options);

if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('story_comment'));
if ($this->form->isValid()) {
$comment = $this->form->save();
$this->redirect('@user_story?title='.$this->story->getSlug());
}
}
}
}
?>


My routing file contains the following routes:
homepage:
url: /
class: sfDomainRoute
param: { module: home, action: index }
user_stories:
url: /verslagen
class: sfDomainRoute
param: { module: profile, action: stories }
user_story:
url: /verslag/:title
class: sfDomainRoute
param: { module: profile, action: storySingle }


In another template I have a link to a certain user_story which works fine:
<?php echo link_to($story->getTitle(), '@user_story?title='.$story->getSlug()) ?>


The problem arises when I fill in the form on the storySingle page and press submit. The following exception is thrown:
404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/verslag/title-of-story" (/).


I did put some debugging code in "lib/vendor/symfony/lib/controller/sfFrontWebController.class.php" and found out that both $moduleName and $actionName are empty because apparently they are not in the request. If I check the request ($this->context->getRequest()) it does have other parameters like the post parameters of my form.

Does anybody have a clue why the module and action are absent from the request?

This question has been answered.

Wouter Peschier | 08/29/10 at 2:02pm Edit


(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    08/29/10
    2:44pm
    Francesco Tassi says:

    Try adding sf_method To ruote definition in routing.yml. If you get 404 posting To a route Maybe you a have To enable post method for that ruote. Check routing reference To get the exact syntax.

    It should work.

    • 08/29/10 2:40pm

      Wouter Peschier says:

      Thanks! Adding the sf_method did indeed fix the problem :)

  • avatar
    Last edited:
    08/29/10
    2:29pm
    Karol Sójko says:

    Try to erase the class attribute in the routings defined

    Previous versions of this answer: 08/29/10 at 2:27pm | 08/29/10 at 2:29pm

  • avatar
    Last edited:
    08/29/10
    2:44pm
    Sergey Kushniruk says:

    You're using sfRequestRoute which extends sfRequestRoute that requires sf_method param to be specified or defaults to GET. So you should specify sf_method param in your routing.yml like this:


    user_story:
    url: /verslag/:title
    class: sfDomainRoute
    param: { module: profile, action: storySingle, sf_method: [get, post] }

    • 08/29/10 2:42pm

      Wouter Peschier says:

      Thanks! The only thing is that you have to put the sf_method as a requirement instead of as a param ;)

      user_story:
      url: /verslag/:title
      class: sfDomainRoute
      param: { module: profile, action: storySingle }
      requirements: { sf_method: [get, post] }

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.