Title: Using html field/shortcode value in calculation
Last modified: June 12, 2022

---

# Using html field/shortcode value in calculation

 *  Resolved [peti73](https://wordpress.org/support/users/peti73/)
 * (@peti73)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/)
 * Hi,
 * first of all thank You for this great plugin!
 * I’d need help with the following:
    how can i use a html field value (or shortcode
   value) in a calculation? I have a shortcode which get an actual metal price (
   via metals-api). I was able to put that shortcode in a html field with this method:
   [using shortcode in forminator](https://wordpress.org/support/topic/using-shortcode-in-forminator/),
   and it displays the price correctly.
 * But then how can i use this field value in a calculation?
    Is there a code or
   workaround to do this?
 * Thank You in advance!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [Imran – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support9/)
 * (@wpmudev-support9)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15730141)
 * Hello [@peti73](https://wordpress.org/support/users/peti73/) !
 * Hope you’re having a good week!
 * Glad to hear you’re finding Forminator useful!
 * As this is not possible out of the box, I’ve asked our Second Line Support team
   to check if this can be achieved using a code snippet to place the value in the
   form for further use. We’ll update you here as soon as we hear back from them.
 * Kind regards,
    Pawel
 *  Thread Starter [peti73](https://wordpress.org/support/users/peti73/)
 * (@peti73)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15730460)
 * Thanks for the information!
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15730530)
 * Hi [@peti73](https://wordpress.org/support/users/peti73/)
 * I hope you are doing well.
 * Our developers created small code to help you:
 *     ```
       <?php
   
       add_filter( 'forminator_field_calculation_markup', 'wpmudev_render_calc_value', 10, 4 );
       function wpmudev_render_calc_value( $html, $id, $required, $value ){
       	if( $id == 'calculation-1-field' ){
       		if( strpos( $html, 'data-formula=""') !== false ){
       			$html = str_replace('data-formula=""', 'data-formula="15*1"', $html);
       		}
       	}
       	return $html;
       }
   
       add_filter( 'forminator_field_calculation_calculable_value', 'wpmudev_render_calc_value_db', 10, 3 );
       function wpmudev_render_calc_value_db( $formula, $prepared_data, $field_settings ){
       	if( $prepared_data['form_id'] != 361 ){
       		return $formula;
       	}
   
       	if( $field_settings['element_id'] == 'calculation-1' ){
       		$formula = '15*1';
       	}
   
       	return $formula;
       }
       ```
   
 * You can add the code as mu-plugin following this guide [https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins](https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins)
 * calculation-1-field , calculation-1 should be changed as per the field settings.
   Form ID should be changed from 361 to your form ID. The developer used this 15*
   1 which should be changed to the value that you get via a shortcode from an external
   API.
 * Best Regards
    Patrick Freitas
 *  Thread Starter [peti73](https://wordpress.org/support/users/peti73/)
 * (@peti73)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15730640)
 * Hi Patrick,
 * unfortunately i cannot follow you.
    I don’t have a “calculation-1-field” – is
   that the html field which displays the shortcode’s value? What formula should
   i put in the “calculation-1” element? Without a formula a cannot add that field.
   How do i change the “15*1” to my shortcode value if i don’t know the value, because
   it will received via that shortcode? Or should i put my shortcode here?
 * I’m sorry I don’t understand.
 *  Plugin Support [Imran – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support9/)
 * (@wpmudev-support9)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15733364)
 * Hello [@peti73](https://wordpress.org/support/users/peti73/) !
 * Apologies for the confusion here!
 * To use the snippet, you will need to add an additional Calculations field (you
   can make it hidden) which will take the value from the shortcode and you will
   be able to use it for further calculations in the other field. The HTML field
   will only be used in this case to display the value to the visitor.
 * So calculation-1-field is the new Calculations hidden field you add for this 
   purpose.
 * In the field you can add a formula such as 0 + 0 just so it has something there.
 * For the 15*1 please change:
 * `$formula = '15*1';`
 * To something like:
 * `$formula = do_shortcode('[your_shortcode]') . '+ 0';`
 * Best regards,
    Pawel
 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15750293)
 * Hello [@peti73](https://wordpress.org/support/users/peti73/) ,
 * We haven’t heard from you for several days now, so it looks like you don’t have
   any more questions for us.
 * Feel free to re-open this ticket if needed.
 * Kind regards
    Kasia

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Using html field/shortcode value in calculation’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [calculation](https://wordpress.org/support/topic-tag/calculation/)
 * [HTML field](https://wordpress.org/support/topic-tag/html-field/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 6 replies
 * 4 participants
 * Last reply from: [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/using-html-field-shortcode-value-in-calculation/#post-15750293)
 * Status: resolved