Forums

Custom server side validation

jvince 31 May, 2009
Hi,
Trying to use the server side validation feature with PHP.
I have added the following PHP code from the Validation tab and set Enable Server Side Validation ? Yes

<?php
if (eregi('http://*.', $comments))
die ("Sorry, no links allowed");

if (eregi('www*.', $comments))
die ("Sorry, no links allowed");
?>


Basically trying to stop any URL links in the comments text field.
The above code works fine on a standalone PHP form, but seems to be ignored by CF.

Any idea what I'm doing wrong?

Many thanks,

- Vince
GreyHead 31 May, 2009
Hi Vince,

Please see the little example by the server-side validation box:
<?php
if($_POST['accept_terms'] != 'yes')
  return 'Sorry, but you need to accept our terms to proceed';
?>
You need to return an error message (or any message in fact). Using 'die' kills the thread but ChronoForms has no way of knowing that's what happened.

Bob
jvince 31 May, 2009
Hi Bob,
So can I just replace 'die' with 'return'?
Excuse my ignorance.

Thanks
GreyHead 31 May, 2009
Hi Vince,

Yes, I think that should work OK.

Bob
jvince 31 May, 2009
Nope, didn't work.
<?php
if (eregi('http://*.', $comments))
return "Sorry, no links allowed";

if (eregi('www*.', $comments))
return "Sorry, no links allowed";
?>


Any ideas?
Thanks
Max_admin 01 Jun, 2009
Hi Vince,

Where is $comments defined ?

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 01 Jun, 2009
Hi Vince,

Sorry I wasn't paying atttention to the content of your filter yesterday - too much sunshine I think.

You have to define $comments - presumably you mean the content of the 'comments' field. In which case
$comments = JRequest::getVar('comments', '', 'post');
But note that this will escape the contents so your filters may not work as you expect them to.

Bob
jvince 01 Jun, 2009
Hi Bob, Max,
Are you saying to just add your code or totally replace mine with yours:
$comments = JRequest::getVar('comments', '', 'post');


Again, apologies I'm not a coder, just a copy and paste expert.
Would you consider adding this type of validation into core CF?
I find it helps reduce form link spammers.
If you do, may be worthwhile considering something similar to WordPress, whereby they give a choice to configure how many, if any at all, limks are allowed.

Many thanks,

- Vince
Max_admin 05 Jun, 2009
Hi Vince,

your code should be:


    <?php
    $comments = JRequest::getVar('comments', '', 'post');
    if (eregi('http://*.', $comments))
    return "Sorry, no links allowed";

    if (eregi('www*.', $comments))
    return "Sorry, no links allowed";
    ?>


the server side validation is more powerful yes, but its left empty so you can customize your rules and errors, if its built in then it would not be that flexible!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jvince 05 Jun, 2009
Brilliant, that works :-)
I told you I am a good copy-paste coder😀

Many thanks,

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