Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi. Not sure anyone is really working on the drupal 7 port but I'm trying to get a redirect working for my block form. Don't want it to go anywhere when they submit my form. Just stay on the current page or maybe homepage. I am using the following with a scattershot approach to test just where in the code I should be calling my $form_state['redirect'] but it's not working in any of these spots!
function formblock_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'node_type_form') {
$options = array(t('Disabled'), t('Enabled'));
$form['formblock'] = array(
'#type' => 'fieldset',
'#title' => t('Form block'),
'#weight' => 10,
);
$form['actions']['submit']['#submit'][]='formblock_submit';
$form_state['redirect'] = '/';
$form['formblock']['formblock_expose'] = array(
'#type' => 'radios',
'#title' => t('Enable data entry from a block'),
'#default_value' => variable_get('formblock_expose_'. $form['#node_type']->type, 0),
'#options' => $options,
'#description' => t('Enable this option to make the entry form for this content type available as a block.'),
);
if($form_id == 'formblock_node_form')
{
$form['actions']['submit']['#submit'][]='formblock_submit';
}
}
function formblock_submit($form, &$form_state) {
$form_state['redirect'] = '/';
}
}
Comments
Comment #1
rumblewand CreditAttribution: rumblewand commentedOk well obviously I want that on the block not the admin stuff so I moved it down here.
still with no success.
Comment #2
rumblewand CreditAttribution: rumblewand commentedGot it. Needed to call it within the formblock_form_alter but outside of the two instances provided.
Comment #3
rumblewand CreditAttribution: rumblewand commentedspoke too soon. that does work for creating the content in a block HOWEVER it prevents you from deleting content once it's created so... suck.
Comment #4
rumblewand CreditAttribution: rumblewand commentedOk. sort of fixed but as of now it loses the system message verifying that the user successfully created anything after submitting the form.
Comment #6
perumal.karthi CreditAttribution: perumal.karthi commentedThanks for this post.
Comment #7
prakash.mukta CreditAttribution: prakash.mukta commentedHi,
Redirection issue is fixed in Drupal 7 and you will get message Node created successfully !! Small modifications to above code
/**
* Implementation of hook_form_alter().
*/
function formblock_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'node_type_form') {
$options = array(t('Disabled'), t('Enabled'));
$form['formblock'] = array(
'#type' => 'fieldset',
'#title' => t('Form block'),
'#weight' => 10,
);
$form['formblock']['formblock_expose'] = array(
'#type' => 'radios',
'#title' => t('Enable data entry from a block'),
'#default_value' => variable_get('formblock_expose_'. $form['#node_type']->type, 0),
'#options' => $options,
'#description' => t('Enable this option to make the entry form for this content type available as a block.'),
);
}
if ($form_id == 'ac_filter_reminder_node_form') {
$form['actions']['submit']['#submit'][]='ac_filter_reminder_submit';
}
}
/*
This function needs to be out of Alter form
*/
function ac_filter_reminder_submit($form, &$form_state) {
$form_state['redirect'] = ''; // U can give path here as per your requirement
}
I hope this will help...
This is my first comment, I am new to this.
If any mistakes plz let me know. Thx
Comment #8
thatpatguy CreditAttribution: thatpatguy commentedadding onto what prakash.mukta posted I made a small tweak for my own specific purpose. I figured I might as well add it here in case someone else is looking to do something similar. This will check to see what language the site is in (for multilanguage website) as well as determine if the person submitting it is logged in or anonymous.