• Resolved Mattmcca

    (@mattmcca)


    Hello I am trying to insert a value from a submitted form into another table, for some reason I am unable to insert into the other table, any assistance would be appericated. Below is my code

    <?php
    /**
    * Plugin Name: [FluentForms] - Fluent Forms Insert Into Database After Form Submission
    * Description: Charge dealer dependent on the number of bookings they have made.
    * Author: Matthias McCarthy
    * License: GPLv2 or later
    * Version: 1.0.0
    */

    add_action('fluentform/submission_inserted', 'charge_dealer_submission_function', 20, 2);

    function charge_dealer_submission_function($entryId, $formId)
    {
    global $wpdb;
    $numberOfBookings = 0;
    $current_user = get_current_user_id();

    // Get the submission data using the entry ID
    $submissionData = wpFluent()->table('fluentform_submissions')->find($entryId);

    // Extract form fields
    $formFields = wpFluent()->table('fluentform_submission_meta')
    ->where('submission_id', $entryId)
    ->get();

    foreach ($formFields as $field) {
    $fieldName = $field->meta_key;
    $fieldValue = $field->value;


    // Check if the field is the one we're interested in
    if ($fieldName == 'numeric_field') { // Corrected from 'field_name' to 'meta_key'
    $numberOfBookings = intval($fieldValue);
    }
    }

    // Insert into Credit_Log if numberOfBookings is greater than 0
    if ($numberOfBookings > 0) {
    $wpdb->query($wpdb->prepare(
    "INSERT INTO Credit_Log (Credits, Action, User_ID, PerformedBy)
    VALUES (%d, %s, %d, %d)",
    -$numberOfBookings, // Credits (negative for deduction)
    'Transaction', // Action
    $current_user, // User_ID
    $current_user // PerformedBy
    ));
    }
    }
    ?>
    • This topic was modified 3 months, 1 week ago by Mattmcca. Reason: More Info
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Amimul Ihsan Mahdi

    (@amimulihsanmahdi)

    Hello @mattmcca,

    While we always strive to assist with general inquiries and ensure you get the most out of Fluent Forms, providing support for custom code solutions falls outside the scope of our support services.

    We recommend seeking help from a developer who can assist with custom code implementations like the one you’re working on.

    We appreciate your understanding, and if you have any questions about Fluent Forms’ built-in features or configurations, feel free to ask!

    Thank you

    Thread Starter Mattmcca

    (@mattmcca)

    <?php
    /**
    * Plugin Name: [FluentForms] - Fluent Forms Insert Into Database After Form Submission
    * Description: Charge dealer dependent on the number of bookings they have made.
    * Author: Matthias McCarthy
    * License: GPLv2 or later
    * Version: 1.0.0
    */

    add_action('fluentform/submission_inserted', 'charge_dealer_submission_function', 20, 3);

    function charge_dealer_submission_function($submissionId, $formData, $form)
    {
    if($form->id != 3) {
    return;
    }

    global $wpdb;
    $numberOfBookings = 0;
    $current_user = get_current_user_id();

    $numberOfBookings = $wpdb->get_var($wpdb->prepare(
    "SELECT value FROM krv_fluentform_entry_details WHERE submission_id = %d AND field_name = %s",
    $submissionId,
    'numeric_field'
    ));

    }
    ?>

    Let me update the question then as i found some of the issues. Every time I submit, $submissionId is returning as null in my code. is there something that I am missing

    Plugin Support Amimul Ihsan Mahdi

    (@amimulihsanmahdi)

    Hello there,

    We have tested the hook submission_inserted on our end and it seems to be working fine, the $submissionId is printed perfectly; please check the screenshot.

    Thank you

    Thread Starter Mattmcca

    (@mattmcca)

    Hi thank you so much I will carry on investigating the issue, I would like to ask . Am I able to use the following items in add_action, since two of these variables are wordpress functions

      global $wpdb;
    $numberOfBookings = 0;
    $current_user = get_current_user_id();
    Thread Starter Mattmcca

    (@mattmcca)

    Hi I managed to solve this issue thank you for all the help that was provided

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.