ionicle Posted August 6, 2013 Share Posted August 6, 2013 Alright, guys and gals, here's my dilemma: I am using the Tectite Formmail script on one of my pages as a "contact form processor". I've set up the script to record the contact email of the person that submits the form, as well as their message, in a file on my server, and then redirect the user to a "Thank you for your enquiry" page. So far so good. What I wanna do is, add a few lines of code to the script so that it does the following upon a successful submission of the form, in this specific order: 1. Record the submitted data as usual. 2. Check whether the email address of the user belongs to a certain domain ( Yahoo!, Gmail, etc. ). That should be executed by checking if the word "yahoo" exists after the "@" symbol in the submission of the "email address" field. By doing that, I will be able to apply the rule for not only @yahoo.com, but for all regional @yahoo derivations. Same would go for Gmail and so forth. 3. If it does, immediately redirect the user to a page different than the default one I've set up in the script. How would I go about doing that? Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/ Share on other sites More sharing options...
The Letter E Posted August 6, 2013 Share Posted August 6, 2013 if( preg_match('YOUR REGEXP HERE', $email_address) ){ //do redirect for custom page header('Location: '.$redirect_link); }else{ //do standard form processing } Above is the basic format that may work for you. You will however need to create the proper regular expression to catch each custom instance of an email address you want to redirect: see this link - http://www.regular-expressions.info/ or this one - http://gskinner.com/RegExr/ or this one - http://regexpal.com/ Reply if you need more help E Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443712 Share on other sites More sharing options...
ionicle Posted August 8, 2013 Author Share Posted August 8, 2013 Do I really need to do this with RegEx? Wouldn't something like that work: if ($_POST['field'] == '@yahoo.') { header('Location: page.php'); "field" is obviously the field name that contains the email address. But, since the email address will not be an exact string "@yahoo.", that will not work. Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443972 Share on other sites More sharing options...
PaulRyan Posted August 8, 2013 Share Posted August 8, 2013 Here is something I threw together, give it a try. <?PHP //### For test purposes $email = '[email protected]'; //### Array of endings and url to go to $emailArray = array('@yahoo.com' => 'URL 1', '@gmail.com' => 'URL 2' ); //### Iterate over each of the array elements to find a match for the email foreach($emailArray AS $ending => $location) { if(strstr($email, $ending)) { $headerLocation = $location; break; } } //### If the ending is matched, re-direct to that url if(isset($headerLocation)) { echo 'Re-directing to: '.$headerLocation; //### If the ending is not match do something else } else { echo 'Normal form processing'; } ?> Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443974 Share on other sites More sharing options...
ionicle Posted August 8, 2013 Author Share Posted August 8, 2013 Yup, that does seem like it's gonna be working. I replaced the example email with: $email = $_POST['email']; where email is the name of the email input field on the submitting page, so it would capture the correct email address. Is that correct? Also, how would you specify a varying "yahoo" domain? So that I can avoid listing all the regional Yahoo domains by hand ( yahoo.de, yahoo.co.uk etc. ). The only constant in that would be "@yahoo." . Gmail doesn't use regional domains, so it wouldn't be an issue. Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443976 Share on other sites More sharing options...
PaulRyan Posted August 8, 2013 Share Posted August 8, 2013 A simple question, with a simple answer. Instead of "@yahoo.com", just use "@yahoo." Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443978 Share on other sites More sharing options...
ionicle Posted August 8, 2013 Author Share Posted August 8, 2013 True that, all fixed and working like a charm! Thank you very much! Link to comment https://forums.phpfreaks.com/topic/280898-conditional-redirect-depending-on-the-presence-of-certain-element-in-the-posted-form-data/#findComment-1443981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.