tooth-paste Posted May 31, 2018 Share Posted May 31, 2018 How can I make a form with a formula. Does anyone have ideas. Example: Inputfield 1: variable #1 Inputfield 2: variable #2 Inputfield 3: variable #3 #1 - #2 -(#3 x 1.8) RESULT Link to comment Share on other sites More sharing options...
bernhard Posted May 31, 2018 Share Posted May 31, 2018 http://lmgtfy.com/?q=javascript+form+formula You just need some very basic HTML + some very basic JavaScript 4 Link to comment Share on other sites More sharing options...
kixe Posted May 31, 2018 Share Posted May 31, 2018 If you need this for the backend (result available in frontend too) you can use FieldtypeMarkup for the result. Grab the code from here: https://github.com/kixe/FieldtypeMarkup Create a hook with your formula and place the code in /site/ready.php The result will be populated after saving the page. /** * https://github.com/kixe/FieldtypeMarkup * FieldypeMarkup as concat field with formula * EXAMPLE * */ $wire->addHookAfter('FieldtypeMarkup::formatValue', function($e) { $page = $e->arguments[0]; $field = $e->arguments[1]; // quick exit if ($field->name != 'result') return; if ($page->template != 'calculator') return; $value1 = $page->inputfield1; $value2 = $page->inputfield2; $value3 = $page->inputfield3; $value4 = $pages->get(12345)->inputfield1; // get value from another page $result = $value3 * ($value2 - $value3) / $value4; // formula $e->return = $result; }); 3 Link to comment Share on other sites More sharing options...
tooth-paste Posted May 31, 2018 Author Share Posted May 31, 2018 Great, I will look into it:) Link to comment Share on other sites More sharing options...
Recommended Posts