I have created several menus in Drupal 7.12 each with an entry saying "Select ...", the idea being that this entry would be displayed but not redirect the user anywhere. Because Drupal menu links must have a valid system path, I have included the path "node/666" which happens to be the front page of the site. At present when the user clicks on the submit button the user is redirected to the front page.
Disabling the menu item simply removes it from the jump menu, as is standard behavior for Drupal menus. Is there some way for deactivate or disable the submit button until a boni-fide selection has been made by the user?
Alternatively, is there something that can be put in the path variable of the menu item would cause Drupal abandon the redirect or redirect the user to the current page?
The current ability to cause the display of the active page would seem to point the way toward a solution, but since these jumpmenu blocks will appear on pages whose nodes are not included as menu items, I can't see this a completely solving the issue.
Comments
Comment #1
deastlack commentedModifying the rendering of the menu items to include the disabled attribute in the first item is not the way to go since that appears to prevent the display of the menu item entirely - not the desired effect.
Since the row weight of the first menu item appears to always be -50, can this number be used in the form building to blank the redirection destination?
Blanking the value of an option tag seems to result in the following error message being displayed: "An illegal choice has been detected. Please contact the site administrator."
Is there some way to capture the path from the URL at run-time and insert that into the value of the option tag for the first option. During menu creation a proxy value could be used for the path, and the URL alias substituted for the proxy during page rendering.
Modifying the submit handler would still require some means to identify the first option, which would mean adding an id to each option during the rendering and sending a flag of some sort to indicate this behavior is desired.
Comment #2
deastlack commentedI have a situation with four jump menus on the page. I have added the following code to my project overrides module:
/**
* Form submit callback for the jump form.
*
* /
function *****_hacks_jump_quickly_form_1_submit_alter($form, &$form_state) {
$form['jump-quickly-form1']['submit']['#submit'] = array('marad_hacks_jump_quickly_form_submit');
}
function *****_hacks_jump_quickly_form_2_submit_alter($form, &$form_state) {
$form['jump-quickly-form-2']['submit']['#submit'] = array('marad_hacks_jump_quickly_form_submit');
}
function *****_hacks_jump_quickly_form_3_submit_alter($form, &$form_state) {
$form['jump-quickly-form-3']['submit']['#submit'] = array('marad_hacks_jump_quickly_form_submit');
}
function *****_hacks_jump_quickly_form_4_submit_alter($form, &$form_state) {
$form['jump-quickly-form-4']['submit']['#submit'] = array('marad_hacks_jump_quickly_form_submit');
}
/**
* REVISED Form submit callback for the jump form.
*
* @param array $form
* @param array $form_state
*/
function *****_hacks_jump_quickly_form_submit($form, &$form_state) {
if (!empty($form_state['values']['jump_goto'])) {
if ($form_state['values']['jump_goto'] = 'node/162') {
} else {
$fragment = explode('#', $form_state['values']['jump_goto']);
if (isset($fragment[1])) {
drupal_goto($fragment[0], NULL, $fragment[1]);
}
else {
drupal_goto($form_state['values']['jump_goto']);
}
}
}
}
In the above code, I've added form item alter functions to redirect the submit handler of the submit button to a modified handler in my project overrides module. In the modified submit handler I've added a check for the path associated with the first option in each jump menu.
Unfortunately the alternative submit handler is not being successfully attached to the form and therefore not called.
Don't have much experience with Hook ..... Alter and this my first shopt a writing modules for D7, so any thoughts would be appreciated!
Don't know if I overlooked something in transitioning from D6 to D7 or what
Thanks
Comment #3
deastlack commentedStill unable to over ride the submit handler.
Unsure whether to override at the 'factory' level or at the individual form level.
I'm confident that my logic in the revised submit handler is valid, the only question remaining is how and where to supplant the original handler. Why is this code not working?
function *****_hacks_form_alter($form, &$form_state, $form_id) {
dsm($form_id); // print form ID to messages
if($form_id == "jump_quickly_form_1") {
dpm($form); // print array to messages
$form['jump_quickly_form_1']['#submit'][] = array('*****_hacks_jump_quickly_form_submit');
return $form;
}
}