HashanChamara / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
0 stars 0 forks source link

validate/handle float values in the same way class validates integers and alphanumeric values. #87

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1.  there are no steps to reproduce this problem
2.  the form builder class has support for validating integers, alphanumeric 
and maybe alpha only fields?  but no support for validating float values
3.  i altered the class to validate (using javascript and server side 
validation) float values.

What is the expected output? What do you see instead?

irrelevant.  i expected the class to do validation of float values but it didn't

What version of the product are you using? On what operating system?

the latest version (1.1.2)

Please provide any additional information below.

I've attached the altered class file for your reference.

i added the following code to the class (line numbers changed but i basically 
took all the test for integers, and beneath them, added tests for floats):

 99   private $floatExists;

 141     $this->floatErrorMsgFormat = "Error: [LABEL] contains one or more invalid characters - only numbers, decimals and signs are allowed.";

 644     if(!empty($ele->float) && empty($this->floatExists))
 645       $this->floatExists = 1;

1085           elseif(!empty($ele->float))
1086             $ele->attributes["class"] .= " pfbc-float";

2131       elseif(empty($this->preventJSValidation) && !empty($ele->float)) {
2132         $errorMsg = str_replace(array("[LABEL]", '"'), array($eleLabel, 
'"'), $this->floatErrorMsgFormat);
2133         $str .= <<<STR
2134   if(formObj.elements["$eleName"].value != "$eleHint" && 
formObj.elements["$eleName"].value != "") {
2135     
if(!formObj.elements["$eleName"].value.match(/^[-+]*[0-9]*\.?[0-9]+$/)) {
2136       js_errors_{$this->attributes["id"]}.push({ errormsg: "$errorMsg", 
container: "{$ele->container}" });
2137       if(js_errors_{$this->attributes["id"]}.length == 1)
2138         formObj.elements["$eleName"].focus();
2139     }
2140   }
2141 
2142 STR;
2143 
2144       }

2239       elseif(empty($errorMsg) && !empty($ele->float) && 
$referenceValues[$ele->attributes["name"]] !== $ele->hint && 
$referenceValues[$ele->attributes["n     ame"]] !== "" && 
!preg_match("/^[-+]*[0-9]*\.?[0-9]+$/", 
$referenceValues[$ele->attributes["name"]]))

i added the last or test to this line:

2941       if(!empty($form->integerExists) || !empty($form->alphanumericExists) 
|| !empty($form->floatExists)) {

i added this code:

2964       if(!empty($form->floatExists)) {
2965         $str .= <<<STR
2966 jQuery("#{$this->attributes["id"]} .pfbc-float").bind("keydown", 
function(event) {
2967   if(jQuery.inArray(event.keyCode, pfbc_allowed_keys) != -1
2968     || (event.keyCode == 67 && (event.ctrlKey || event.metaKey))
2969     || (event.keyCode == 86 && (event.ctrlKey || event.metaKey))
2970     || (event.keyCode == 109)
2971     || (event.keyCode == 107)
2972     || (event.keyCode == 190)
2973     || (!event.shiftKey && ((event.keyCode >= 48 && event.keyCode <= 57) 
|| (event.keyCode >= 96 && event.keyCode <= 105)))
2974   )
2975     return true;
2976   else
2977     return false;
2978 });
2979 
2980 STR;

3828   public $float;

Original issue reported on code.google.com by rj05cole...@gmail.com on 9 Nov 2010 at 2:25

Attachments:

GoogleCodeExporter commented 8 years ago
I believe this was a duplicate entry.

Original comment by ajporterfield@gmail.com on 9 Nov 2010 at 3:04