Conditional Redirect for email input

By: Amber Prince | Asked: 06/17/2022
ForumsCategory: Code HelpConditional Redirect for email input
Amber Prince asked 2 years ago
Hi, currently utilizing a form to have a "login" field where user inputs email address and if the domain is correct they get redirected to a page. We need to have a redirect in place for when a user inputs an email not recognized by our whitelist and they get sent to another page - this redirect needs to be able to account for all different email domains.  Here is current code snippet setup that support provided: 
add_filter('frm_redirect_url', 'return_page', 9, 3);
function return_page($url, $form, $params){
      if($form->id == 664){ //change 5 to the ID of the form to redirect
      $field_id = 15678; //change 25 the the ID of your field
              $postedvalue = $_POST['item_meta'][$field_id]; //We are storing the value submitted in the field in the variable $postedvalue. And we will create our logic using that variable.
              if(strpos($postedvalue, '@yahoo') !== false || strpos($postedvalue, '@google') !== false || strpos($postedvalue, '@facebook') !== false ) //If the value submitted contains @yahoo (You can modify that your preferred string)
         $url = '';
         else if(strpos($postedvalue, '@amazon') !== false || strpos($postedvalue, '@ebay') !== false || strpos($postedvalue, '@next') !== false)
         $url = '';
return $url;
With the code above, if the email contains @yahoo or @google or @facebook, you will be redirected to If the email contains @amazon or @ebay or @next, you will be redirected to  Ideally, need to adjust to function like the "if like" "if not like" conditionals - i.e. 
[if 45 like=""][/if 45]
[if 45 not_like=""][/if 45] 
so there is a catch all solution for domains not accounted for. Currently the redirect doesn't happen but instead a blank white page opens with no messaging.  Appreciate any insight anyone can provide. 
1 Answers
Victor Font answered 2 years ago
You can include an else in Formidable conditionals: [if 45 like=""][else][/if 45]
Amber Prince replied 2 years ago

Can this be used with multiple email addresses/domains? I tried [if 45 like="; [email protected]"] and [if 45 like=", [email protected]"] and it redirects to error page.

We usually have a few domains and at least 1 individual email address we need to whitelist - otherwise the "else" would be perfect. 🙁

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community