[SOLVED] terms&conditions validation problem
Posted: Tue Sep 04, 2012 9:08 am
Hi guys,
I'm trying to modify a plugin written for the cms getsimple. The plugin is written to generate forms. I want to use the plugin to add a terms&conditions button. No problem to add a checkbox or a radio but whatever you accept or not the terms&condition statements, the plugin always send the email (it simply add the preference to the email). I want that the code will stop you if you don't accept the policy. So...
Here is the whole php file (too long): http://www.sendspace.com/file/aielhr
This is the part of code I'm tryng to modify:
The plugin already include a validation system. I've just tryed to add:
with an html code like that:
<div class="field radio">
<div class="label"><label for="p01-contact1_field4">I accept the terms&conditions<strong style="color:red">*</strong></label></div>
<input id="p01-contact1_field4_option0" type="radio" name="p01-contact_fields[4]" value="yes" />yes
<input id="p01-contact1_field4_option1" type="radio" name="p01-contact_fields[4]" value="no" checked />no</div>
But It doesn't work... the page return the error "field_radio" in any case (yes or no).
Any idea? I've also tryed something like
Thanks!!!
I'm trying to modify a plugin written for the cms getsimple. The plugin is written to generate forms. I want to use the plugin to add a terms&conditions button. No problem to add a checkbox or a radio but whatever you accept or not the terms&condition statements, the plugin always send the email (it simply add the preference to the email). I want that the code will stop you if you don't accept the policy. So...
Here is the whole php file (too long): http://www.sendspace.com/file/aielhr
This is the part of code I'm tryng to modify:
Code: Select all
*
* Check if field is empty and required or
* not empty but not valid.
* @return string the error key, or empty
*/
public function check_content()
{
if(empty($this->value) && $this->required) {
// empty and required
return 'field_required';
}
elseif(!empty($this->value) && !$this->check_validity()) {
// not empty but not valid
return 'field_' . $this->type;
}
else return '';
}
/**
* Check if field value is valid
* Mean different things depending on field type
* @return boolean
*/
public function check_validity()
{
if($this->blacklisted()) return False;
switch($this->type) {
case 'email':
$pattern = '`^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$`i';
if(preg_match($pattern, $this->value)) return True;
else return False;
case 'phone':
$pattern = '`^\+?[-0-9(). ]{6,}$$`i';
if(preg_match($pattern, $this->value)) return True;
else return False;
case 'website':
$pattern = "`^((http|https|ftp):\/\/(www\.)?|www\.)[a-zA-Z0-9\_\-]+\.([a-zA-Z]{2,4}|[a-zA-Z]{2}\.[a-zA-Z]{2})(\/[a-zA-Z0-9\-\._\?\&=,'\+%\$#~]*)*$`i";
if(preg_match($pattern, $this->value)) return 1;
else return False;
case 'message':
$size = strlen($this->value);
if($size > $this->form->settings('message_len')) return True;
else return False;
case 'captcha':
include_once CAPTCHAPATH . 'securimage.php';
$securimage = new Securimage();
if($securimage->check($this->value) == False)
return False;
else return True;
case 'fieldcaptcha':
if(!empty($this->value)) return False;
else return True;
case 'password':
if($this->value == $this->required)
return True;
else return False;
default:
return True;
}
}Code: Select all
case 'radio':
if($this->value == "yes")
return True;
else return False;
<div class="field radio">
<div class="label"><label for="p01-contact1_field4">I accept the terms&conditions<strong style="color:red">*</strong></label></div>
<input id="p01-contact1_field4_option0" type="radio" name="p01-contact_fields[4]" value="yes" />yes
<input id="p01-contact1_field4_option1" type="radio" name="p01-contact_fields[4]" value="no" checked />no</div>
But It doesn't work... the page return the error "field_radio" in any case (yes or no).
Any idea? I've also tryed something like
Code: Select all
if($_post['p01-contact_fields[4]'] == "yes"))