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
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
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
Hi Vince,
Please see the little example by the server-side validation box:
Bob
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
Nope, didn't work.
Any ideas?
Thanks
<?php
if (eregi('http://*.', $comments))
return "Sorry, no links allowed";
if (eregi('www*.', $comments))
return "Sorry, no links allowed";
?>
Any ideas?
Thanks
Hi Vince,
Where is $comments defined ?
Max
Where is $comments defined ?
Max
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
Bob
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
Hi Bob, Max,
Are you saying to just add your code or totally replace mine with yours:
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
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
Hi Vince,
your code should be:
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
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
This topic is locked and no more replies can be posted.