2

Forms API question on how to redirect from one form to another, depending on checkbox field

http://drupal.org

Hello,

After submitting a form, I want my users to be redirected to another form if a checkbox is checked. The drupal path I want to redirect to is 'node/add/organization' . So far my checkbox displays fine. I am using hook_form_alter() to add the new checkbox field and include my custom function in the $form['#submit'] array of functions.

Here's my custom function's code:

<?php
function my_custom_function($form, $form_state) {
    if (isset($form['redirect_checkbox']['#value']['redirect'])) {
        $form_state['redirect'] = 'node/add/organization';
    }
}
?>

This however is not doing the trick.

Some more info I found hacking around my local development environment:
- I used the watchdog() function to see what functions are being called when I click on submit. Here's what I got (in order of execution) : node_form_validate, node_form_submit, menu_node_form_submit, my_custom_function
- I also add a watchdog to see what parameters are going to drupal_redirect_form() and saw that it was being called with $form_state['redirect'] = 'node/222'

Any help would be appreciated, thanks.

Read »
Created by Dplanet 1 year 16 weeks ago
Category: Modules   Tags:

PSD to Drupal Theme

Drupal Development

Module Development

Get an Estimate

Best published scoops - Modules

Tags for Forms API question on how to redirect from one form to another, depending on checkbox field

Recent comments