Pass parameter to UDT in formbuilder

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
pierrepercee
Forum Members
Forum Members
Posts: 164
Joined: Thu Jan 10, 2013 8:02 am

Pass parameter to UDT in formbuilder

Post by pierrepercee »

Hello,

to protect my form i want to know time spent on page before submission. If this value is under 5 seconds then the form will not be send. Robots fill the form in a micro second perhaps.
UDT Integration->User defined tag to call before form is displayed the first time (only called once):
I created a UDT named 'debtime' with this code :

Code: Select all

$secondesdebut=time();
$smarty->assign('secondesd', $secondesdebut);
Now i can call a second UDT (named 'howmanysec'
Form submission
User defined tag to call during form validation

But i don't know how to catch {$secondesd} value in this howmanysec UDT. I can't pass param as usual. And I don't know if I can stop form sending inside my UDT
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1974
Joined: Mon Jan 29, 2007 4:47 pm

Re: Pass parameter to UDT in formbuilder

Post by Jo Morg »

I would use the form validation UDT option:
Validation UDT. Set this for a form, and the UDT will receive all of the form's human-readable results. The UDT should do whatever validation it wants, and return an array with the first value being true or false (indication whether the form validates), and the second value being error messages (if any)
To store the timestamp for when the form was rendered I'd go for a session var that I would use to compare on the validation UDT. Mind you: that might stop bots for a while but, as most anti-spam measures, it can be shortcut by a few attempts made by a human assisted bot until it learns how to bypass the measure.
But still worthwhile trying as it may prevent spam for quite a long while.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
brambaud
Forum Members
Forum Members
Posts: 11
Joined: Mon Apr 18, 2011 8:38 am

Re: Pass parameter to UDT in formbuilder

Post by brambaud »

Hi,
To detect a robot, another basic method is to add a hidden field to the user.
if it is filled, it can only be by a robot, in which case the form must not be validated.
French CMSMS websites maker
pierrepercee
Forum Members
Forum Members
Posts: 164
Joined: Thu Jan 10, 2013 8:02 am

Re: Pass parameter to UDT in formbuilder

Post by pierrepercee »

Hello Jo Morg,

Thanks for the session var I will give it a try !
No doubt it is possible to bypass such a protection, but it is much less trivial than a simple hidden field.

@brambaud
This form already contains hidden field. Honeypot was very efficient some years ago, today.... not really.
pierrepercee
Forum Members
Forum Members
Posts: 164
Joined: Thu Jan 10, 2013 8:02 am

Re: Pass parameter to UDT in formbuilder

Post by pierrepercee »

Hello,

You don't need to use UDT validation.
Create two UDT:

First one :

udtone

Code: Select all

session_start();
$secdebut=time();
$_SESSION['debut60mn']=$secdebut;
Call it here : UDT Integration->User defined tag to call before form is displayed the first time (only called once):

Second :
udttwo

Code: Select all

$debsec=$_SESSION['debut60mn'];
$last=time();
$totsec=$last-$debsec;
if ($totsec < 4){
echo "<h1>You completed this form in less than 4 seconds. That's too short a time for a human, even a very fast one. This form was therefore not sent, sorry. </h1>";return array(false);}
else
{return array(true);}

Call it here:
Tab : Form submission
->User defined tag to call during form validation

That's all. Works like a charm ! :)

Many thanks Jo Morg for the session var idea ! ;)
Post Reply

Return to “Modules/Add-Ons”