Development

#3184 (UrlHelper.php button_to function does not work correctly with query_string option)

You must first sign up to be able to contribute.

Ticket #3184 (closed defect: fixed)

Opened 4 months ago

Last modified 2 months ago

UrlHelper.php button_to function does not work correctly with query_string option

Reported by: jillelaine Assigned to: FabianLange
Priority: minor Milestone: 1.0.15
Component: helpers Version: 1.0.11
Keywords: UrlHelper button_to broken Cc:
Qualification: Unreviewed

Description

UrlHelper?.php button_to function does not work correctly with query_string option

link_to works correctly:

echo link_to('Edit Page', $pagename, array('query_string'=>'edit=true') );

produces this correct code in 'view source'

<a href="/mypage?edit=true">Edit Page</a>

But same code with button_to does not work correctly

echo button_to('Edit Page', $pagename, array('query_string'=>'edit=true') );

produces this code in 'view source' -> it is missing the query_string on the end of the URL and doesn't work.

<input query_string="edit=true" value="Edit Page" type="button" onclick="document.location.href='/mypage';" />

Proposed change to UrlHelper?.php to make query_string work correctly with button_to function:

function button_to($name, $internal_uri, $options = array())
{
  $html_options = _convert_options($options);
  $html_options['value'] = $name;

  if (isset($html_options['post']) && $html_options['post'])
  {
    if (isset($html_options['popup']))
    {
      throw new sfConfigurationException('You can\'t use "popup" and "post" together');
    }
    $html_options['type'] = 'submit';
    unset($html_options['post']);
    $html_options = _convert_options_to_javascript($html_options);

    return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).tag('input', $html_options).'</form>';
  }
  else if (isset($html_options['popup']))
  {
    $html_options['type'] = 'button';
    $html_options = _convert_options_to_javascript($html_options, $internal_uri);

    return tag('input', $html_options);
  }
  //begin query string hack
  else if (isset($html_options['query_string']))
  {
    $html_options['type']    = 'button';
    $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."?".$html_options['query_string']."';";
    unset($html_options['query_string']);
    
    return tag('input', $html_options);
  }
  //end query string hack
  else
  {
    $html_options['type']    = 'button';
    $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';";
    $html_options = _convert_options_to_javascript($html_options);

    return tag('input', $html_options);
  }
}

This fixes the problem

http://www.symfony-project.org/forum/index.php/m/48293/#msg_48293

Change History

05/07/08 18:21:45 changed by FabianLange

  • owner changed from fabien to FabianLange.
  • status changed from new to assigned.
  • milestone set to 1.0.15.

05/07/08 18:51:41 changed by FabianLange

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

(In [8837]) fixed some issues with butto_to helper, query string is now appended correctly, short notation of attributes is parsed correctly, some internal refactoring and unit tests. fixes #3184

05/07/08 18:52:43 changed by FabianLange

actually r8836 is for 1.0.15