Forums

prevent duplicate submission

mariospapa 16 Jan, 2011
How can I prevent a guest from submitting twice, a public chronoform??? In other words, how can I check that a certain e-mail address has submitted this form?
GreyHead 16 Jan, 2011
Hi mariospapa,

You can use Server Side validation to check if the Email is already in the data table.

Bob
mariospapa 18 Jan, 2011

Hi mariospapa,

You can use Server Side validation to check if the Email is already in the data table.

Bob



Thank you Bob,

and how can i write a simple php script in order to check if an e-mail exists, when i have Database0 with Table0 and name, email are the two fields of the Table0?
mariospapa 18 Jan, 2011
I wrote code below and put it to "ServerSide Validation" of chronoform and enable the corresponding option!


<?php
mysql_connect ("localhost", "user","password")  or die (mysql_error());
mysql_select_db ("database");

$checkmail = $_POST['email'];
$res = mysql_query("SELECT email FROM Table1 WHERE email = '$checkmail');

if(mysql_num_rows($res) != 0) {
    echo 'You have already submit the current form';
}
?>


But it doesn't work! Why?
GreyHead 19 Jan, 2011
Hi Mariospapa,

The code isn't very Joomla! and the ServerSide validation needs to set a 'return' value if there is an error (see the example on the ToolTip). Is your table really called Table1?

Please try:
<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(`email`)
        FROM `Table1`
        WHERE `email` = '$checkmail' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
    return 'You have already submit the current form';
}
?>

Bob
mariospapa 19 Jan, 2011
Hey Bob... thank you for helping me...

The code that you provide me, doesn't work... I think that by submission of the form, the whole thing doesn't pass from this validation code... The real name of the table that contains email field is "jos_chronoform_form1".
GreyHead 19 Jan, 2011
Hi mariospapa,

It's fairly standard validation and it should work OK unless I've left typos in there. The FROM line probably becomes FROM `#__chronoforms_form1`

Bob
mariospapa 20 Jan, 2011
This one is working great! You have forgotten one comma in JRequest::getString...

<?php
$checkmail = JRequest::getString('email', '', 'post');
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(`email`)
        FROM `#__chronoforms_form1`
        WHERE `email` = '$checkmail' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
    return 'You have already submit the current form';
}
?>



Thanks for helping me again!
GreyHead 20 Jan, 2011
Hi mariospapa,

Sorry about the typo :-(

I fixed my original post in case someone else copies it.

Bob
This topic is locked and no more replies can be posted.