Closed modxuser closed 6 years ago
I've got tired to answer questions that are answered in the docs.
@Pathologic
I am sorry to bore you with my questions, If I could have found the information I would not have asked the question
Why don't you simply point me to the right place ? and not just say, read the docs.
Thank you
Not being a PHP developer, I would never have known that that information does what the "eformOnBeforeMailSent" event does, even after reading it
We are sadly not all PHP savvy, that's something that should be taken into consideration, I am sure @dmi3yy knows this
Your code shall be:
<?php
$FormLister->setField('remote_addr', $_SERVER['REMOTE_ADDR']);
$FormLister->setField('remote_host', $_SERVER['REMOTE_HOST']);
$FormLister->setField('user_agent', $_SERVER['HTTP_USER_AGENT']);
or
<?php
$FormLister->setFields(array(
'remote_addr' => $_SERVER['REMOTE_ADDR'],
'remote_host' => $_SERVER['REMOTE_HOST'],
'user_agent' => $_SERVER['HTTP_USER_AGENT']
));
Save it to snippet and point this snippet in prepare or prepareProcess parameter.
Thank you very much - can I get you a coffee / beer ?
Some more examples:
//prepare-snippet to deny form procession if given name is foobar
$name = $FormLister->getField('name'); // $name = $data['name'] can be written as well
if ($name == 'foobar') {
$FormLister->setValid(false);
}
//prepare-snippet to manual field validation
$name = $FormLister->getField('name');
if ($name == 'foobar') {
$FormLister->addError('name', 'foobar', 'Your name cannot be foobar');
}
//prepareProcess-snippet to make report more nice
$data['message'] = nl2br(strip_tags($data['message']));
$data['name'] = ucfirst($data['name']);
$data['phone'] = empty($data['phone']) ? 'none' : $data['phone']; // assume that phone is not required field but we want to write 'none' in report if user has left it blank
return $data; // $FormLister->setFields($data) can be written as well
Snippets from prepare parameter are run before form validation, from prepareProcess - after form validation but before the main controller action (sending mail or creating user etc.) Sorry, but full usage of this feature requires to study PHP a bit.
https://github.com/Pathologic/FormLister/blob/master/assets/snippets/FormLister/docs/examples/ru/006_%D0%94%D0%B2%D0%B0_%D0%BD%D0%B0%D0%B1%D0%BE%D1%80%D0%B0_%D0%BF%D0%BE%D0%BB%D0%B5%D0%B9.md - in this examples validation rules and report depend on radio button value.
I have set it to "prepareProcess" but tested both and both work
Yes, but prepare-snippets are executed every time, while prepareProcess - only once. There's no difference in this particular case, but it can be if you are working with DB or CURL.
Thank you for the in-depth explanations, they have given me a better understanding of what I am doing - hopefully I can portray that in a further tutorial for others to use
In general eForm events are too limited and more difficult to understand. Prepare-snippets are closer to Revo's FormIt hooks.
@Pathologic
How can I get you a beer ?
It's a big problem in case of my country, so don't mention ((:
OK, thanks again for all your help, it's very much appreciated and it not only helps me, it will help others to understand better
Indeed, you both are doing a great job, much appreciated! Especially when all those infos will be added into evo-docs!
Information added to Evolution Docs, can be found here
Is there an equivalent of the following for FormLister ?
I use this to run a snippet that gets the basic server information of the sender
The snippet code: