0

I'm using Ninja Forms and their extension to do front-end posts. They have a function that isn't working that is supposed to allow you to redirect to a specific "thank you" page depending on values from the form (you specify the form field ID). This is the code but it isn't working:

function change_ninja_forms_landing_page(){
    global $ninja_forms_processing; 

    $form_id = $ninja_forms_processing->get_form_ID(); 

    if( $form_id == 1 ){ 
        $swapcategory = $ninja_forms_processing->get_field_value( 21 ); 

        switch( $swapcategory ){ 
            case 'Need':
                $url = 'http://dcartistexchange.org/start-swapping/need/';
                break;
            case 'Offer':
                $url = 'http://dcartistexchange.org/start-swapping/offers/';
                break;
        }

        // $url now contains our new success page. Let's update the form setting.
        $ninja_forms_processing->update_form_setting( 'landing_page', $url );
    }
}

Field 21 is a custom post type category checkbox and the "case" are the field values. When I submit the form, nothing happens (I get the form submitted confirmation but it doesn't go to the pages specified).

I've tried putting wp_redirect in there (with the exit) and that doesn't seem to work either. Can anyone see what I may be missing?

1 Answer 1

1

You never initialize the value in $url. Test the value in $swapcategory. When there is no match, $url is empty and that may be the problem. This comment is false:

// $url now contains our new success page. Let's update the form setting.

It should say:

// $url may contain our new success page or it may be unset.
1
  • Thanks! I knew I was missing something, I just couldn't figure out what it was. Aug 7, 2013 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.