Page 1 of 1

[SOLVED] terms&conditions validation problem

Posted: Tue Sep 04, 2012 9:08 am
by long_road
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:

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;
}
}
The plugin already include a validation system. I've just tryed to add:

Code: Select all

case 'radio':
if($this->value == "yes")
return True;
else return False;
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

Code: Select all

if($_post['p01-contact_fields[4]'] == "yes"))
Thanks!!!

Re: terms&conditions validation problem

Posted: Tue Sep 04, 2012 4:39 pm
by long_road
I've solved the problem by myself!

The solution is:

Code: Select all

case 'radio':
            if($_POST['p01-contact_fields'][4] == "yes")
             return True;
            else return False;
To be added below line 873 in p01-contact.php

I still have to set a specific error message (now it return a red write "field_radio") but I am happy!!!