Home › Forums › Quform WordPress › Make Calculations on Fields
- This topic has 2 replies, 2 voices, and was last updated 10 years, 11 months ago by lawrencepepper.
- AuthorPosts
- February 14, 2014 at 8:33 pm #8731lawrencepepperParticipant
Hello,
I have a problem that I am trying to solve and need advice on the best way to accomplish it.
I need to calculate a value to be inserted into my database based on what number a person enters into a field. This calculation needs to be done against a number which needs to be gotten with a query to my database.
Example:
I need to query my database and get the current users hourly rate and overtime rate then pass these values to my quform.
On the form my user will be filling out two fields, one for regular hours and one for overtime hours.
I then need to take the number they enter and times it by their hourly rate that I passed to the form and calculate the amount of money they are owed.
This amount then needs to get inserted into the database using the Quform custom database settings.
In my functions file if I add this:
#Get Current Users Regular Ratefunction mytheme_get_regularrate($value)
{
if (is_user_logged_in()) {
global $current_user;
get_currentuserinfo();
$person = $current_user->user_login;
}$con = mysql_connect("localhost","xxx","xxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("time", $con);
$result = mysql_query("SELECT * FROM employee WHERE user_name = '$person'");
while($row = mysql_fetch_array($result))
$value = $row['rtrate'];
return $value;
}
add_filter('iphorm_element_value_regularrate', 'mytheme_get_regularrate');How can I then use this variable in my forms to do the calculations I need. Or is there a better way?
February 17, 2014 at 11:43 am #8753AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 17, 2014 at 5:51 pm #8763lawrencepepperParticipantThanks for the suggestion. I decided to do the calculating on the server side to be safe.
L
- AuthorPosts
- You must be logged in to reply to this topic.