This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 3
Customization and derived form data
Started 12 years ago by christopherbrooks | 6 posts |
-
For those who need custom logic to derive fields from a combination of user input fields, this is quite feasible. Appnitro provided outstanding support to me so I could add this to my forms, and I share it for the benefit of all.
Background:
My form collects user input for many selections -- check boxes and number counts mainly. My need was to calculate a total fee, which is based on a combination of things selected, not simply a one-price-per-item. I also wanted to show the total fee to the user on the review page. I am running version 3.3.Solution:
The customization takes place in post-functions.php. About line 320, immediately before
//pick user input
add this code:/** Initialize input from session **/ $temp_input = $input; unset($temp_input['form_id']); unset($temp_input['submit_form']); unset($temp_input['page_number']); unset($temp_input['submit_primary']); unset($temp_input['submit_secondary']); foreach ($element_to_get as $el_name) { $key_temp = array(); $key_temp = explode("_",$el_name); if(count($key_temp) >= 3){ if(!empty($_SESSION['all_page_input_'.$form_id][$el_name]) && empty($input[$el_name])){ unset($_SESSION['all_page_input_'.$form_id][$el_name]); } } } $_SESSION['all_page_input_'.$form_id] = (array) array_merge((array) $_SESSION['all_page_input_'.$form_id],$temp_input); $input = array_merge($input,$_SESSION['all_page_input_'.$form_id]); /** end initialization **/
Follow this with your own custom code to derive data based on the user input. You can refer to any of your form's fields and base your calculations and logic on whatever value (numbers, check boxes, radio buttons, etc) the user has supplied. For example:
$lunchfee = (int) $input['element_29'] * $satlunchfee + $input['element_38'] * $sunlunchfee ;
When your calculations are complete, you can push the results into one or more hidden fields -- not shown on the input form , but visible on the review page:
$input['element_60'] = strval($PartAFeeTot) ; $input['element_61'] = strval($PartBFeeTot) ; $input['element_62'] = strval($PartAFeeTot + $PartBFeeTot);
Your calculations are totally behind the scenes, but you can make results appear on the review page and thus become part of the submitted form.
My compliments to Appnitro for a terrific software package and excellent support.
Posted 12 years ago # -
I really need to get something like this working so a few questions - sorry if these are basic.
How do you know what "element" # is which field?
How do you create a "hidden" field that is not shown on the input form but is on the review page?How can you determin which item on a line is selected in a matrix choice?
Thanks
Posted 12 years ago # -
Follow up
Solved: How do you know what "element" # is which field? Use View Source in browser.
Solved: How do you create a "hidden" field that is not shown on the input form but is on the review page? Use "hidden" in custom CSS
Solved:How can you determin which item on a line is selected in a matrix choice? Element value is set to the column user selectsPosted 12 years ago # -
New Questions:
How do you know which form you are processing within the PHP code of post-functions.php so the derived fields only work on the forms I want them to?
Can you set the value of "Guidelines for User" in a Section Break via PHP like you can the value of an element?Thanks
Posted 12 years ago # -
You can check the value of $form_id variable. It contain the ID number of your form.
You can override/set the value of the guidelines by modifying the view-functions.php file, around line 4098:
$element[$j]->guidelines = $row['element_guidelines'];
MachForm Founder
Posted 12 years ago # -
Thanks - this worked. Now I can check which form is being processed and create calculated data based on the form.
Posted 12 years ago #
Reply
You must log in to post.