Make Calculations on Fields

Home Forums Quform WordPress Make Calculations on Fields

This topic is: resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8731
    lawrencepepper
    Participant

    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 Rate

    function 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?

    #8753
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #8763
    lawrencepepper
    Participant

    Thanks for the suggestion. I decided to do the calculating on the server side to be safe.

    L

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy