Jump to content

Formula calculation form


tooth-paste
 Share

Recommended Posts

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;
    });

 

 

  • Like 3
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...