This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
[closed] limit number of fields by user
Started 16 years ago by walags | 8 posts |
-
This is what I would like to accomplish...say you have 50 drop down fields and you only want a user selecting a response for 10 of them, where do I start?
I am assuming there is an easy function to see if a field is empty or not. Similar to the checking in place for required fields, I want to count how many fields are empty and prevent the user from submitting if it is more or less then I say so. In the example above I would want to have a total of 40 empty fields...no more no less.
Could you see a function like this work in this environment?
Posted 16 years ago # -
Hi ..
From your case you only want user to fill 10 from 50 Drop down right? you can try this modification to your machform :
1. modify includes/post-functions.php
#bellow line 131
//count variable $selectRequiredCount = 0;
#between line 630 ~ 632, replace
if($validation_result !== true){ $error_elements[$element_id] = $validation_result; }
to
//add rule blank check $rules[$element_name]['blank'] = true; if($validation_result !== true){ if ($validation_result !== "BLANK") $error_elements[$element_id] = $validation_result; else $selectRequiredCount++; }
#in line 948, add
if ($selectRequiredCount <> 40) { $process_result['status'] = false; $process_result['custom_error'] = "you must fill 10 entries"; return $process_result; }
2. modify include/common-validator.php
#in line 39
//validation for blank function validate_blank($value){ $value = $value[0]; if(empty($value)) { //0 and '0' should not considered as empty return 'BLANK'; }else{ return true; } }
MachForm Support
Posted 16 years ago # -
Wow, thanks for the quick response. It is not currently working for me. I edited the error message to output the $selectRequiredCount value. It doesn't appear that this variable is being incremented.
Where does the new function validate_blank get called?
Posted 16 years ago # -
Really ? have you put bellow code to include/common-validator.php , and try echo the $selectRequiredCount in line 948 it should show the value.
//validation for blank function validate_blank($value){ $value = $value[0]; if(empty($value)) { //0 and '0' should not considered as empty return 'BLANK'; }else{ return true; } }
MachForm Support
Posted 16 years ago # -
do you have another piece of code i need to add? i'm not too sure how everything is set up but i don't see where you called validate_blank function. $selectRequiredCount remains zero.
if you have these two files working can you just email them to wal_ags at yahoo?
Posted 16 years ago # -
I'm sorry my bad ..
the code in that line supposed like this around line 630 ~ 632
//add rules blank $rules[$element_name]['blank'] = true; $target_input[$element_name] = $element_data; $validation_result = validate_element($target_input,$rules); if($validation_result !== true){ if ($validation_result !== "BLANK") $error_elements[$element_id] = $validation_result; else $selectRequiredCount++; }
MachForm Support
Posted 16 years ago # -
man yall are good. at a minimum yall should have a paypal donate button for custom stuff like this.
i don't see it being an issue since i will only have one form active at a time, but can i limit this new requirement to a specific form number?
Posted 16 years ago # -
you can change this code
$rules[$element_name]['blank'] = true;
to
if ($form_id == 1) {$rules[$element_name]['blank'] = true; }
and thank you for suggestion :D
MachForm Support
Posted 16 years ago #
Topic Closed
This topic has been closed to new replies.