Forums

Limit field responses. Reference/coupon code validation

ericbecky 17 Aug, 2010
Hello,
I have a form where people are required to enter in a reference/coupon code.
Currently I use a text box for this. But how it's set up now, people can type in any jumble of text and the form still goes through.

I want to check the entry against my list of "official" reference codes. And if they do not use one of the official codes I don't want the form to go through. I would also display a quick message stating "this is not a valid code" if it is not a code from the list. I don't want them to choose the items from a drop down list, since I don't want to visibly publish all the codes for everyone to see.

How can I do this?

If it is a standard feature of Chrnoforms and I missed it I apologize.
I've done some searching for "coupon" and "reference" on this forum and did not find the answer.

The form can be seen at http://greendriveexpo.com/greendriveexpocoupon
ericbecky 18 Aug, 2010
O.k. I found this referenced on another chronoforms thread

var f14 = new LiveValidation('f14');
f14.add( Validate.Inclusion, { within: [ 'cow' , 'pigeon', 'giraffe' ] } );



It looks like I could use this code... if only I knew where and how to implement it. :-)

For now I
1) went to the tab labeled "form code"
2) clicked on the little +/- next to "Form JavaScript:" in the "Main onLoad/View Code" area.
3) pasted the above code in that area. (I changed f14 to the variable name I am checking: text_11)
So it looks like this

var text_11 = new LiveValidation('text_11');
text_11.add( Validate.Inclusion, { within: [ 'sept123' , 'oct416', 'nov223' ]} );


4) clicked on save at the top of the form.

But the form does not seem to be doing the validation.

Do I also need to go to the "Validation" tab and change the "Enable Validation" to "Yes"?
I tried that, but it did not seem to make a difference either.

Thanks in advance for the help.
GreyHead 18 Aug, 2010
Hi ericbecky ,

There are two main ways to do this. The simple one is to use the ChronoForms Serverside validation box to check the result against an approved list (presumably in a database table). The more complicated one is to use Ajax in the form to do a real-time lookup when the code is entered (that's not too difficult either). You'd still need the server-side check for backup so I'd be inclined to code that first and then add the Ajax as a later 'improvement'.

Bob
ericbecky 01 Sep, 2012
Due to a time crunch I ended up hiring an outside person to code it for $50.
He was my request.
http://www.freelancer.com/projects/PHP-Joomla/PHP-server-side-verification-script.html

He made a database table named "jvredirect" that can be directly accessed via the php database back end of the website.
Additionally, a more user friendly way to access it is via a link he made on the Joomla "Components" dropdown menu.

On the validation tab of Chronoform form he did a few things.
In the ServerSide Validation section he set "Enable Server Side Validation" to "Yes".
Then in the Server Side validation Code box he entered the following:

<?php
$db =& JFactory::getDBO();
$id=JRequest::getString('code');
$id=strtolower ($id);
$id=$db->getEscaped( $id );
$query = "SELECT * FROM #__jvredirect where name='".$id."'";
$db->setQuery( $query);
$row = $db->loadObjectList();
if ($db->getErrorNum()||count($row)==0) {

return 'That is not a valid Discount Code. Please check your code and enter it again.' ;
}

?>

If a person enters a code that does not match one from the list they get the error message.

On the jvredirect table has 3 fields
ID (This is an internal auto-increment that makes a unique id#
Code (This is the text that is checked against)
Description (This is a description so I remember what the code means for tracking purposes)

I added this post as a reference for myself.
Max_admin 03 Sep, 2012
Thanks for sharing!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ericbecky 03 Sep, 2012
When I get around to it, I should really add some more code so that I can activate or inactivate the code.
That way I could use a code for an event, and then later turn it off after the event was over.
Or even better, but much more complex would be to add a timeframe in which the code was active.
Max_admin 03 Sep, 2012
That should not be very complex, we are trying continuously to improve Chronoforms in order to give users more abilities and make complicated issues much easier🙂
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.