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