<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: perform a calculation and change values being submitted.</title>
		<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted</link>
		<description>Gravity Support Forums Topic: perform a calculation and change values being submitted.</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 23:38:11 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/perform-a-calculation-and-change-values-being-submitted" rel="self" type="application/rss+xml" />

		<item>
			<title>Idealien on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3950</link>
			<pubDate>Fri, 12 Mar 2010 16:39:54 +0000</pubDate>
			<dc:creator>Idealien</dc:creator>
			<guid isPermaLink="false">3950@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;How would you (or is there a way to) identify the _POST values by name rather than input_7 / etc?&#60;/p&#62;
&#60;p&#62;I'd like to use something similar to generate a password string via PHP and add it into a hidden field and have it display in the email notification. Atleast until the feature for user generation is in place :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3727</link>
			<pubDate>Wed, 03 Mar 2010 13:46:21 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">3727@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Very nice! Glad you figured it out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3719</link>
			<pubDate>Wed, 03 Mar 2010 06:06:43 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3719@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Cracked it. I'm posting the code in case another user wants to do something similar. With some modification this can be used for scoring surveys, etc.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_pre_submission&#38;quot;, &#38;quot;pre_submission_handler&#38;quot;);
function pre_submission_handler($form_meta){
    global $_POST;

    if($form_meta[&#38;quot;id&#38;quot;] != &#38;#39;1&#38;#39;){
        return;
    }

    $calculation = (($_POST[&#38;quot;input_2&#38;quot;] / $_POST[&#38;quot;input_1&#38;quot;]) - 1) * 100;
    $_POST[&#38;quot;input_7&#38;quot;] = $calculation;
	$_POST[&#38;quot;input_1&#38;quot;] = &#38;#39;0&#38;#39;;
	$_POST[&#38;quot;input_2&#38;quot;] = &#38;#39;0&#38;#39;;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Thanks again for your help.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3718</link>
			<pubDate>Wed, 03 Mar 2010 05:24:07 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3718@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;DOH!&#60;/p&#62;
&#60;p&#62;What a beginners mistake...&#60;/p&#62;
&#60;p&#62;Got another question on how I can make sure this only runs for one form but I'll open another topic for that.&#60;/p&#62;
&#60;p&#62;Many thanks for your help, the plugin is everything I wanted and more and I'll be sure to recommend it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3700</link>
			<pubDate>Tue, 02 Mar 2010 13:14:01 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">3700@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;jorges,&#60;br /&#62;
You were close. Only needed to declare the $_POST variable as global. Try the following:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_pre_submission&#38;quot;, &#38;quot;pre_submission_handler&#38;quot;);
function pre_submission_handler($form_meta){
    global $_POST;

    $calculation = (($_POST[&#38;quot;input_2&#38;quot;] / $_POST[&#38;quot;input_1&#38;quot;]) - 1) * 100;
    $_POST[&#38;quot;input_3&#38;quot;] = $calculation;
    echo $_POST[&#38;quot;input_3&#38;quot;];
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3694</link>
			<pubDate>Tue, 02 Mar 2010 11:27:16 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3694@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;That would be very helpful. Many thanks.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Kevin Flahaut on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3692</link>
			<pubDate>Tue, 02 Mar 2010 11:20:51 +0000</pubDate>
			<dc:creator>Kevin Flahaut</dc:creator>
			<guid isPermaLink="false">3692@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;We'll get our lead developer to take a look at this one and offer a suggestion. We're always busy with other support requests as well so please be patient and we'll get back to you as soon as possible with something.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3691</link>
			<pubDate>Tue, 02 Mar 2010 10:59:07 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3691@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;It would be nice if someone would tell me if I'm wasting my time here or will this request be eventually looked at.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3683</link>
			<pubDate>Tue, 02 Mar 2010 05:32:01 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3683@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;bump
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jorges on "perform a calculation and change values being submitted."</title>
			<link>https://legacy.forums.gravityhelp.com/topic/perform-a-calculation-and-change-values-being-submitted#post-3660</link>
			<pubDate>Mon, 01 Mar 2010 12:14:07 +0000</pubDate>
			<dc:creator>jorges</dc:creator>
			<guid isPermaLink="false">3660@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I'm trying to take the values entered in two fields in a given form and perform a calculation with them before storing the result on the database. I'm also trying to set the two field's values to 0 before storing the result.&#60;/p&#62;
&#60;p&#62;Currently I'm using the pre_submission_handler hook and I can access my values and calculate them.&#60;/p&#62;
&#60;p&#62;What I'm stuck with is how do I then go about setting the values that are going to be submitted to the database to whatever I want.&#60;/p&#62;
&#60;p&#62;Being a complete newbie at php I managed to somehow get to this:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_pre_submission&#38;quot;, &#38;quot;pre_submission_handler&#38;quot;);
function pre_submission_handler($form_meta){
	$calculation = (($_POST[&#38;quot;input_2&#38;quot;] / $_POST[&#38;quot;input_1&#38;quot;]) - 1) * 100;
	$_POST[&#38;quot;input_3&#38;quot;] = $calculation;
	echo $_POST[&#38;quot;input_3&#38;quot;];
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This displays the right calculation but does not store it on the database.&#60;br /&#62;
Any help would be greatly appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
