Conditional Redirect: Can anyone help me please?
-
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(“SELECTname
FROM$wpdb->prefix" . "table
WHEREname
= %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
- The topic ‘Conditional Redirect: Can anyone help me please?’ is closed to new replies.