Development

#8170 (url_for_form fails if used with an sfForm object; it should require sfFormObject)

You must first sign up to be able to contribute.

Ticket #8170 (closed defect: fixed)

Opened 2 months ago

Last modified 1 month ago

url_for_form fails if used with an sfForm object; it should require sfFormObject

Reported by: joshcoady Assigned to: fabien
Priority: minor Milestone: 1.4.2
Component: helpers Version: 1.4.1
Keywords: UrlHelper Cc:
Qualification: Unreviewed

Description

Doing something like:

echo form_tag_for($form, "@article?category_id={$category->id}")

Will result in a routing error when you submit the form because the url generated for the form's action will be something like article?category_id=29_create

This is because url_for_form doest detect if routes starting with @ are using extra parameters.

To fix this issue, just change the following part of url_for_form

  if ('@' == $routePrefix[0])
  {
    $format = '%s_%s'; 
    $routePrefix = substr($routePrefix, 1);
  }

To

  if ('@' == $routePrefix[0])
  {
    $format = '%s_%s';
    $routeParts = explode('?', $routePrefix, 2);
    $routePrefix = $routeParts[0];
    if(count($routeParts) == 2)
    {
      $format .= "?{$routeParts[1]}";
    }
  }

Change History

01/30/10 07:36:16 changed by joshcoady

  • summary changed from url_for_form does not handle routes with extra parameters properly to url_for_form fails if used with an sfForm object; it should require sfFormObject.

After working with this and testing it some more, I have come to realize that it works the way it is intended. I should have paid more attention to the name of the $routePREFIX parameter. Also, once I finally noticed it was hard-coded to call $form->getObject() that was another big clue.

Though since it does always call getObject(), the $form input parameter should require a type of sfFormObject rather than sfForm.

02/02/10 19:45:15 changed by Kris.Wallsmith

  • milestone set to 1.4.2.

02/08/10 20:24:40 changed by Kris.Wallsmith

  • status changed from new to closed.
  • resolution set to fixed.

(In [27753]) [1.3, 1.4] fixed helper signature (closes #8170)

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.