Forums

[SOLVED] Server Side Validation of Checkbox

YOOlabs 12 Dec, 2012
Hi,
I have a Joomla 1.5/Chronoforms 3.2 Installation.
I have a contact form which is flooded by Spam the last weeks.
The client-side validation doesn´t work, because for example there are cryptical inputs in email fields allthough it is checked for a correct email address syntax.
I also have a requiered Checkbox field:

<div class="form_item">
		<div class="form_element cf_checkbox">
			<div class="float_left">
				<input value="check 1" title="" class="radio validate-one-required" id="check00" name="check0[]" type="checkbox" />
				<label for="check00" class="check_label">Ja, ich habe die <a href="index.php?option=com_content&view=article&id=9&Itemid=17" target="_parent">AGB</a> gelesen und akzeptiere diese.</label>
			</div>
		</div>
	</div>


When somone correctly checked the box and submits the form, the database entry of the form field value is "check 1".

Then, with help of the forum I managed to set up a server side validation of the checkbox field.:

<?php
$messages = array();

$agree = JRequest::getString('check0', 'empty', 'post');
if ( $agree == 'empty' ) {
$messages[] = "Bitte bestätigen Sie die AGB.";
}
// check if there are any error messages and return
if ( count($messages) ) {
return implode('<br />', $messages);
}
?>


But...When I look at the database entries of the spam entries, there is a value in the form field, like the string "Bestimmtes Thema". So this value seems to be inserted by the spam bot and the serverside validation "thinks" that it is a correct value.

Then I tested this server side validation:

<?php
$messages = array();

$agree = JRequest::getString('check0', 'empty', 'post');
if ( $agree != 'check 1' ) {
$messages[] = "Bitte bestätigen Sie die AGB.";
}
// check if there are any error messages and return
if ( count($messages) ) {
return implode('<br />', $messages);
}
?>


But then also my usual form submits run into this error, even if I check the Checkbox.

Am I missing something here?

Thanks in advance!
Malte
GreyHead 12 Dec, 2012
Hi YOOlabs,

I'm not completely clear what the problem is here. You need to build server-side validation that does the best filtering that you can devise. I can't advise you on what is a good result and what isn't.

A honey-trap might help here. There is a FAQ on building one for CFv4 that you could adapt for CFv3.2 (and there may be instructions for 3.2 in the forums here if you search).

Bob
YOOlabs 18 Dec, 2012
Hi GreyHead,
the honeypot was the solution. Thanks and merry Christmas in advance :-)
This topic is locked and no more replies can be posted.