1

I'm using Ninja Forms and their extension to do front-end posts. They have a function that is supposed to allow you to redirect to a specific page depending on values from the form.

my purpose is to have a form, in which the user writes a text, and is then redirected to a customized url according to the test he writes in a given field of the form. So something like "URL"/[the text written in the given field] I've tried something like this but it is not working. Does anyone could help me on this ?

thank you in advance

function change_ninja_forms_landing_page(){
global $ninja_forms_processing; 

$form_id = $ninja_forms_processing->get_form_ID(); 

if( $form_id == 1 ){ 
    $destinationurlslug = $ninja_forms_processing->get_field_value( 1 ); 
    $url = "http://www.blablabla.com";
    $newdestinationurl = $url/$destinationurlslug ;

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

closed as off-topic by Milo, Pieter Goosen, Mark Kaplun, TheDeadMedic, Howdy_McGee Sep 14 '15 at 18:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

I am not sure whether you have hooked this function to appropriate action. Also you have not concatenated the strings properly:

Instead of $newdestinationurl = $url/$destinationurlslug ; it should be $newdestinationurl = $url."/".$destinationurlslug ;

Please see below for the complete code:



function ninja_forms_handler() {
  add_action ( 'ninja_forms_post_process', 'change_ninja_forms_landing_page', 1, 2 );
}
add_action('init', 'ninja_forms_handler');

function change_ninja_forms_landing_page(){
    global $ninja_forms_processing; 

    $form_id = $ninja_forms_processing->get_form_ID(); 

        if( $form_id == 1 ){ 
        $destinationurlslug = $ninja_forms_processing->get_field_value( 1 );         
        $url = "http://www.blablabla.com";
        $newdestinationurl = $url."/".$destinationurlslug ;        
        /* $url now contains our new redirection page. Let's update the form setting. */
        $ninja_forms_processing->update_form_setting( 'landing_page', $newdestinationurl ); 
    }     
}

Make sure if you use this method that you do not have an actual redirect notification created or it will take precedence. So simply deactivate the "Success Message" from "Emails & Actions" tab for your form.

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