• Resolved Lethalmiko

    (@lethalmiko)


    I want to achieve the following:

    1. Submitted form triggers custom code via the WP Hook action.
    2. Custom code runs a search.
    3. If there is a hit, it redirects to a specified page.
    4. If there is no hit, user is redirected back to original form.

    I have already coded everything except that I cannot get the conditional redirect to work, even after combing through the online documentation and trying several things. My code which isn’t working is:

    //Select custom single variable data
    function select_var($sql, $offset = 0) {
    global $wpdb;
    $data = $wpdb->get_col($sql);
    return $data;
    }

    //Form processor
    function form_processor($form_data) {
    global $wpdb;
    $siteurl = get_bloginfo(‘url’) . ‘/’;

    $form_fields = $form_data[‘fields’];
    $data = array();

    foreach($form_fields as $field) {
    $field_key = $field[‘key’];
    $field_value = $field[‘value’];
    }

    // Search
    $name = ‘some_name’;
    $search = select_var($wpdb->prepare(“SELECT name FROM $wpdb->prefix" . "table WHERE name = %s”, $name));

    if($search[0])
    {
    $redirect_url = $siteurl . “success/”;
    wp_redirect($redirect_url);
    exit;
    }
    else
    {
    $redirect_url = $siteurl . “form/”;
    wp_redirect($redirect_url);
    exit;
    }
    }
    add_action(‘ninja_forms_processing’, ‘form_processor’); //WP Hook in the form

    • This topic was modified 6 years, 4 months ago by Lethalmiko.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Conditional Redirect: Can anyone help me please?’ is closed to new replies.