Looking for ideas to conditionally redirect page on submisison

Mustafa_s

Member
Been away for Fabrik so I'm a little rusty at the moment. I have 1 field element (postalverifyhomepage___postalcode) in my form that is used so the user can enter their postal code, for which I have a regex ensuring the proper postal code format is used.

What I would like is to redirect the user depending on the postal code used. I will have 1000 postal codes (perhaps in two database joins). If the user enters a postal code that matches any table in database join "PostalOK" then he should be redirected to /pageA, If the user enters a postal code that matches any table in database join "PostalNO" then he should be redirected to /pageB.

What I have done so far is enabled two redirect plugins on my form with the following:

RedirectA:

Jump page: /pageA
Condition: return '{postalverifyhomepage___postalcode_raw}' == 'xxxxxx';

RedirectA:

Jump page: /pageB
Condition: return '{postalverifyhomepage___postalcode_raw}' == 'yyyyyy';

Question:

What is the proper syntax in the Condition field to match any value that is found in database join "PostalOK" or "PostalNO"? Also, I want to ensure there are no spaces in the input field for field element postalverifyhomepage___postalcode and it's all lowercase.

Thank you.
 
When you say "in two database joins", that doesn't really make sense. Do you just mean you have two tables of post codes, and you want to figure out which one (if any) the code they entered in a simple text field matches against?

If so ...

Code:
$poCode = '{postalverifyhomepage___postalcode_raw}' ;
$poCode = str_replace(' ', '', strtolower($poCode));
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('*')->from('postal_ok')->where('code = ' . $myDb->quote($poCode));
$myDb->setQuery($myQuery);
$myResult = $myDb->loadResult();
return !empty($myResult);

Change the table and field names in the query to suit.

-- hugh
 
Hi Hugh,

Your assumption is correct, that is what I wanted to achieve. Without having access to Fabrik in front of me at the moment I had a brain freeze moment, your suggestion works like a charm.

I have a follow-up question, once I'm on the jump page (let's say /pageA) is there a way to retrieve the submitted value and use it in a custom Javascript somewhere on that page? Ideally I want to display a small google maps using the postal code that was submitted.

Thank you.
 
Just append it to the query string of your jump page, using a placeholder, like &pocode={postalverifyhomepage___postalcode_raw}

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top