Posted by rj on March 27, 2009 at 8:34pm
Jump to:
| Project: | Jump |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | nicholas.alipaz |
| Status: | active |
Issue Summary
Hi, how do I use a URL with special characters? If I use "&" or "?" in the URL, Drupal encodes it into plain text, and then the page I jump_quickly to has an incorrect URL. For example:
<?php
global $user;
$options = array(
'products/56?v1=AND&v2=6' => t('Link Title')
);
print jump_quickly($options);
?>sends the user to www.example.com/products/56%3Fv1%3DAND%2526v2%3D6 but I really want it to point to www.example.com/products/56?v1=AND&v2=6. Any help would be appreciated.
Comments
#1
As a follow up, I ended up hard-coding the URL into the array and it works the way I want it to. I know hard-coding isn't best practices, but hey, it works. So to anyone facing the same problem, this is how your code should look if you want special characters in your path:
<?phpglobal $user;
$options = array(
'http://example.com/products/56?v1=AND&v2=6' => t('Link Title')
);
print jump_quickly($options);
?>
#2
Thanks cultiv8, this info concerning the url encoding was quite helpful.
#3
#4
Hi,
I also have this situation. Here is how I dealt with the problem. I know the code is not yet good, but I will share the idea. I haven't got the time to furnish the code..
<?php
function jump_quickly_form_submit($form, &$form_state) {
if (!empty($form_state['values']['jump_goto'])) {
$fragment = explode('#', $form_state['values']['jump_goto']);
/*grab the get variable values.. can loop with the $_GET values except $_GET['q']*/
$product = $_GET['tid_1'];
$category = $_GET['tid'];
$language = $_GET['language'];
$value = $form_state['values']['jump_goto'];
/*process query string*/
if($product || $category || $language)
{
$query_string = "tid_1=".$product."&tid=".$category."&language=".$language;
$value_frag = explode('?',$value);
$value = $value_frag[0];
}
if (isset($fragment[1])) {
drupal_goto($fragment[0], $query_string, $fragment[1]);
}
else {
drupal_goto($value,$query_string);
}
}
}
?>
<?php
function jump_quickly_form(&$form_state, $options, $menu_state) {
$default = '';
$product = $_GET['tid_1'];
$category = $_GET['tid'];
$language = $_GET['language'];
$query_string = '';
if($product || $category || $language)
{
$query_string = "?tid_1=".$product."&tid=".$category."&language=".$language;
}
$value = $_GET['q'].$query_string;
if ($menu_state['active'] === 1) {
if (isset($options[$_GET['q']])) {
$default = $_GET['q'];
}
//process the default active
else if(isset($options[$value]) && $query_string != '')
{
$default = $_GET['q'];
$default .= $query_string;
}
}
$form = array();
$form['#submit'][] = 'jump_quickly_form_submit';
$form['#theme'] = 'jump_quickly_form';
$form['#attributes']['class'] = 'jump-quickly';
$form['jump_goto'] = array(
'#type' => 'select',
'#default_value' => $default,
'#options' => $options
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Go')
);
if (variable_get('jump_use_js_' . $menu_state['delta'], 0) === 1) {
// Give each menu a unique name.
$form['#attributes']['name'] = 'jumpquickly' . $menu_state['delta'];
$form['#attributes']['class'] .= ' js-enabled';
// unset($form['submit']);
if (variable_get('jump_add_select_' . $menu_state['delta'], 0) === 1) {
$form['jump_goto']['#attributes']['class'] = 'first-no-jump';
// Add the extra empty select option to the top of the array.
$form['jump_goto']['#options'] = array('' => variable_get('jump_add_select_text_' . $menu_state['delta'], t('Select Option'))) + $options;
$form['jump_goto']['#default_value'] = (array_key_exists($default, $options)) ? $default : '';
}
}
return $form;
}
?>
#5
dr3ads, not only did you not use code tags to show your code, but I can't really work with a section of code taken from the module. Please try putting it together as a patch if you're serious about helping us fix this issue.
#6
nicholas, still working on the project. Will work on the patch after I am done with this project. Also, I am very new to contributing works on modules. I still have to read details about this..
Thanks!
-dr3ads