Hi,
I have a competition entry form setup that's working fine except a few people insist on filling it in 15-20 times per day.
I've done a search on the forum and found the following code that I've customised to my situation (own database and field name):
However, it doesn't stop the form from being submitted if an email address has already been saved in the database.
I've put it into a Custom server side validation box which I have put after the Auto Server Side Validation in the On Submit event. OnSuccess is blank and OnFail is an Event loop.
I'm probably making a really silly mistake with this, but I can't work it out. Any help would be really appreciated.
Thanks,
Matt
I have a competition entry form setup that's working fine except a few people insist on filling it in 15-20 times per day.
I've done a search on the forum and found the following code that I've customised to my situation (own database and field name):
<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(`email`)
FROM `jos_chronoforms_data_DiscoverDogs2011`
WHERE `email` = '$checkmail' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
return 'You have already entered the competition';
}
?>
However, it doesn't stop the form from being submitted if an email address has already been saved in the database.
I've put it into a Custom server side validation box which I have put after the Auto Server Side Validation in the On Submit event. OnSuccess is blank and OnFail is an Event loop.
I'm probably making a really silly mistake with this, but I can't work it out. Any help would be really appreciated.
Thanks,
Matt
Hi Matt,
The serverside validation has slightly different syntax in CFv4. Please try
Bob
The serverside validation has slightly different syntax in CFv4. Please try
. . .
if ( $count ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('You have already entered the competition');
return false;
}
?>
Bob
Thank you so very much🙂 Works perfectly
I have been searching for hours on how to make this happen. I'm not sure, but I think it was easier under the old ChronoForms, but I could be wrong.
Anyway, I tried this code (modified with my specifications) and the following happened.
I got an error (see below), it still submitted my data to the database (even though the email exists) and I received a notification email. It also looks as though some sort of debug mode came on that wasn't there before and showed me everything that happened to the form submission (any way to turn that off?).
Here was what was printed on the page (minus private info):
Parse error: syntax error, unexpected T_VARIABLE in .../administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11
Data Array:
Array
(
[chronoform] => newsletter
[event] => submit
[option] => com_content
[view] => featured
[Itemid] => 101
[email] => xxx
[chrono_verification] => LStGw
[input_submit_4] => Submit
[xxx] => 1
[chronoform_data] => Array
(
[cf_uid] => xxx
[cf_created] => 2012-12-18 15:47:18
[cf_created_by] => 0
[cf_ipaddress] => xxx
[cf_user_id] => 0
[chronoform] => newsletter
[event] => submit
[option] => com_content
[view] => featured
[Itemid] => 101
[email] => xxx
[chrono_verification] => LStGw
[input_submit_4] => Submit
[xxx] => 1
[cf_id] => 11
)
[chronoform_data_cf_id] => 11
)
Validation Errors:
Array
(
)
Debug Data
Core Captcha
Passed the core captcha check!
email
10
Result An email has been SENT successfully from
Attachments array ( )
redirect_user
Error: No Redirect URL found
And here is the Server Side code I placed OnSubmit (and after the Captcha has been validated).
<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(`email`)
FROM `jos_chronoforms_data_newsletter`
WHERE `email` = '$checkmail' ;
";
$db->setQuery($query);
if ( $count ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('this email is already registered');
return false;
}
?>
Also, all of this stuff prints on the page even when the email doesn't exist in the db. Like I said - it's in some debug mode that wasn't there before.
Any help on what I'm missing?
Anyway, I tried this code (modified with my specifications) and the following happened.
I got an error (see below), it still submitted my data to the database (even though the email exists) and I received a notification email. It also looks as though some sort of debug mode came on that wasn't there before and showed me everything that happened to the form submission (any way to turn that off?).
Here was what was printed on the page (minus private info):
Parse error: syntax error, unexpected T_VARIABLE in .../administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11
Data Array:
Array
(
[chronoform] => newsletter
[event] => submit
[option] => com_content
[view] => featured
[Itemid] => 101
[email] => xxx
[chrono_verification] => LStGw
[input_submit_4] => Submit
[xxx] => 1
[chronoform_data] => Array
(
[cf_uid] => xxx
[cf_created] => 2012-12-18 15:47:18
[cf_created_by] => 0
[cf_ipaddress] => xxx
[cf_user_id] => 0
[chronoform] => newsletter
[event] => submit
[option] => com_content
[view] => featured
[Itemid] => 101
[email] => xxx
[chrono_verification] => LStGw
[input_submit_4] => Submit
[xxx] => 1
[cf_id] => 11
)
[chronoform_data_cf_id] => 11
)
Validation Errors:
Array
(
)
Debug Data
Core Captcha
Passed the core captcha check!
10
Result An email has been SENT successfully from
Attachments array ( )
redirect_user
Error: No Redirect URL found
And here is the Server Side code I placed OnSubmit (and after the Captcha has been validated).
<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(`email`)
FROM `jos_chronoforms_data_newsletter`
WHERE `email` = '$checkmail' ;
";
$db->setQuery($query);
if ( $count ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('this email is already registered');
return false;
}
?>
Also, all of this stuff prints on the page even when the email doesn't exist in the db. Like I said - it's in some debug mode that wasn't there before.
Any help on what I'm missing?
I found a line of code I missed, but that still didn't help.
$count = $db->loadResult(); was missing after requesting the db query.
If I take out all of the server-side script, I get no parse error, but I still get the debugging stuff.
$count = $db->loadResult(); was missing after requesting the db query.
If I take out all of the server-side script, I get no parse error, but I still get the debugging stuff.
HI applebox,
Please try putting {} round the $checkmail variable in the query
Bob
Please try putting {} round the $checkmail variable in the query
<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(`email`)
FROM `jos_chronoforms_data_newsletter`
WHERE `email` = '{$checkmail}' ;
";
$db->setQuery($query);
$count = $db->query();
if ( $count ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('this email is already registered');
return false;
}
?>
Bob
Thanks for the response Bob.
That did cure the error, however, it still seems to be in some sort of Debug mode and it's also allowing the duplicate entry to be made.
Since the site is still in beta and being developed, I'll send you a link to the front end in a PM and also set you up a login to the back end so you can check it out if you get a chance.
Thanks again,
Mike
That did cure the error, however, it still seems to be in some sort of Debug mode and it's also allowing the duplicate entry to be made.
Since the site is still in beta and being developed, I'll send you a link to the front end in a PM and also set you up a login to the back end so you can check it out if you get a chance.
Thanks again,
Mike
Hi Mike,
I made a few changes - removed the Debugger action and some other unused actions. Moved the Custom SS action out of the Check Captcha action; updated the code to CFv4 and added the Event Loop in the On Fail action so that it should now work correctly.
I haven't tested though.
Bob
I made a few changes - removed the Debugger action and some other unused actions. Moved the Custom SS action out of the Check Captcha action; updated the code to CFv4 and added the Event Loop in the On Fail action so that it should now work correctly.
I haven't tested though.
Bob
Thanks Bob,
I think it's getting close.
I'm getting the following error:
Parse error: syntax error, unexpected '.' in /administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11
Where you had "#__chronoforms_data_newsletter" I put in the actual path, but that didn't help.
I looked at the custom_serverside_validation.php page and line 11 is "var $formname;"
I can't see anywhere in the code that would screw that up since we aren't calling the form name, just the field and the field name is correct.
Mike
I think it's getting close.
I'm getting the following error:
Parse error: syntax error, unexpected '.' in /administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11
Where you had "#__chronoforms_data_newsletter" I put in the actual path, but that didn't help.
I looked at the custom_serverside_validation.php page and line 11 is "var $formname;"
I can't see anywhere in the code that would screw that up since we aren't calling the form name, just the field and the field name is correct.
Mike
Hi Mike,
Unlike JavaScript PHP doesn’t use var declarations (except in class definitions). You can probably just delete this line. What is the rest of the code you have there?
Bob
I looked at the custom_serverside_validation.php page and line 11 is "var $formname;"
Unlike JavaScript PHP doesn’t use var declarations (except in class definitions). You can probably just delete this line. What is the rest of the code you have there?
Bob
This is the code for the whole custom_server_side_validation.php page.
<?php
/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @license GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
**/
defined('_JEXEC') or die('Restricted access');
class CfactionCustomServerSideValidation{
var $formname;
var $formid;
var $events = array('success' => 0, 'fail' => 0);
var $group = array('id' => '1_validation', 'title' => 'Validation');
var $details = array('title' => 'Custom Server Side Validation', 'tooltip' => 'Run PHP code and switch the execution path based on the result.');
function run($form, $actiondata){
$code = $actiondata->content1;
$return = eval('?>'.$code);
if($return === false){
$this->events['fail'] = 1;
}else{
$this->events['success'] = 1;
}
}
function load($clear){
if($clear){
$action_params = array(
'content1' => ''
);
}
return array('action_params' => $action_params);
}
}
?>
I commented it out and I'm still getting "Parse error: syntax error, unexpected '.' in /administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11"
I can't see an ambiguous '.' anywhere in the code. By looking at some posts here, a lot of people are using Custom Server Side validations and I haven't seen this issue. I'm surprised.
<?php
/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @license GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
**/
defined('_JEXEC') or die('Restricted access');
class CfactionCustomServerSideValidation{
var $formname;
var $formid;
var $events = array('success' => 0, 'fail' => 0);
var $group = array('id' => '1_validation', 'title' => 'Validation');
var $details = array('title' => 'Custom Server Side Validation', 'tooltip' => 'Run PHP code and switch the execution path based on the result.');
function run($form, $actiondata){
$code = $actiondata->content1;
$return = eval('?>'.$code);
if($return === false){
$this->events['fail'] = 1;
}else{
$this->events['success'] = 1;
}
}
function load($clear){
if($clear){
$action_params = array(
'content1' => ''
);
}
return array('action_params' => $action_params);
}
}
?>
I commented it out and I'm still getting "Parse error: syntax error, unexpected '.' in /administrator/components/com_chronoforms/form_actions/custom_serverside_validation/custom_serverside_validation.php(19) : eval()'d code on line 11"
I can't see an ambiguous '.' anywhere in the code. By looking at some posts here, a lot of people are using Custom Server Side validations and I haven't seen this issue. I'm surprised.
This topic is locked and no more replies can be posted.