• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Custom Variables and Conditional Email Responses

Custom Variables and Conditional Email Responses 3 weeks 4 days ago #44016

  • greg20
  • greg20's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
I am using RSForm! Pro v3.3.16 with Joomla 5 to power a Quote Request form that includes dynamic fee calculation and an auto-generated Estimate ID. The form is mostly working, but I am encountering several critical issues.

Setup
  • Using default email templates with {fieldname:value} syntax
  • Using standard hidden fields, Single Value dropdowns, and text inputs
  • Using Script called on form process to calculate the estimate using the standard standard form fields
  • Using Script called before the User Email is sent to create the estimate_id and write to log
  • Using User Email HTML to send conditional results to prospect
  • Scripts are cleanly structured and tested
  • No overrides or 3rd-party RSForm plugins involved

Working Features
  • Calculations working in Script called on form process to generate total_quote
  • Estimate ID is successfully calculated using the submission ID and saved to the database.
  • The correct estimate_id appears in the RSForm submission manager.
  • The Estimate ID calculation and database update occur in the Script called before the User Email is sent section.
  • Logging confirms all PHP steps complete without errors (generation, assignment, DB write).

Problem 1: Estimate ID Not Rendering in Email
  • Script location: Script called before the User Email is sent
  • Script correctly generates a unique estimate ID using the Submission ID
  • Log entries confirm estimate ID is generated and saved to the database
  • Hidden field estimate_id exists and is confirmed in the submission record

Script called before the User Email is sent
$log_path = JPATH_SITE . '/administrator/logs/quote_email_debug.log';
 
// -- 1. Start logging
file_put_contents($log_path,
"[" . date('c') . "] EMAIL SCRIPT STARTED.\n",
FILE_APPEND
);
 
// -- 2. Get Submission ID
$submission_id = isset($SubmissionId) ? (int) $SubmissionId : 0;
 
// -- 3. Generate Estimate ID
$estimate_id = 'EST-' . date('Y') . '-' . (10000 + $submission_id);
$_POST['form']['estimate_id'] = $estimate_id;
$userEmail['estimate_id'] = $estimate_id;
$userEmail['property_type']   = $_POST['form']['Property Type'] ?? '';
$userEmail['inspection_type'] = $_POST['form']['Inspection Type'] ?? '';
$userEmail['total_quote']     = $_POST['form']['total_quote'] ?? '';
 
// -- 4. Log generated estimate ID
file_put_contents($log_path,
"[" . date('c') . "] Estimate ID generated: $estimate_id | Submission ID: $submission_id\n",
FILE_APPEND
);
 
// -- 5. Save estimate ID to submission table
if ($submission_id > 0) {
try {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->update($db->quoteName('#__rsform_submission_values'))
->set($db->quoteName('FieldValue') . ' = ' . $db->quote($estimate_id))
->where($db->quoteName('SubmissionId') . ' = ' . $db->quote($submission_id))
->where($db->quoteName('FieldName') . ' = ' . $db->quote('estimate_id'));
$db->setQuery($query);
$db->execute();
 
    file_put_contents($log_path,
        "[" . date('c') . "] Estimate ID successfully saved to database.\n",
        FILE_APPEND
    );
} catch (Exception $e) {
    file_put_contents($log_path,
        "[" . date('c') . "] ERROR saving Estimate ID to database: " . $e->getMessage() . "\n",
        FILE_APPEND
    );
}
}
Logs
[2025-07-09T17:08:28-05:00] EMAIL SCRIPT STARTED.
[2025-07-09T17:08:28-05:00] estimate_id generated: EST-2025-10523 | Submission ID: 523
[2025-07-09T17:08:28-05:00] estimate_id successfully saved to database
PHP Email Template Snippet
  • Tried using all field names
  • <p><strong>Estimate ID: estimate_id:value</strong> {estimate_id:value}</p>
    <p><strong>Estimate ID: estimate_id</strong> {estimate_id}</p>
    <p><strong>Estimate ID: userEmail:estimate_id</strong> {userEmail:estimate_id}</p>
    None of these render in the email output (field is blank or field name shown).
    Estimate ID: estimate_id:value
    Estimate ID: estimate_id {estimate_id}
    Estimate ID: userEmail:estimate_id {userEmail:estimate_id}


    Problem 2: Conditional Logic Fails in Email Template
    • My name is Test28 and I'm interested in a Standard Inspection
    • Property Type: Single Family
    • Street: .....
    • City, State Zip Code
    • Approx. Square Feet: 2489
    • Approx. Year Built: 1901
    {if {Property Type:value} == "Single Family" AND {Inspection Type:value} == "Standard Inspection"}
      <!-- Show estimate details -->
    {else}
      <!-- Show fallback message -->
    {/if}
    Even though dropdown values are correctly set and saved (confirmed in the submission table), the conditional sometimes renders both blocks or the wrong one. We've verified:
    • No extra spaces in dropdown values
    • Values match exactly what’s used in the conditional
    • Field types are dropdowns with single select only
    Any help is appreciated — especially guidance on:
    • Correct way to expose $userEmail[...] variables to the email template
    • Known limitations on conditional logic in email templates
    • Proper way to ensure {estimate_id} renders after assignment in "Script called before the User Email is sent"

    Thank you.
    The administrator has disabled public write access.

    Custom Variables and Conditional Email Responses 3 weeks 1 day ago #44018

    • iceferret
    • iceferret's Avatar
    • OFFLINE
    • Gold Boarder
    • Posts: 250
    • Thank you received: 65
    Problem 1. i think the issue is that your script generates and saves the estimate_id to the database, but does so after the form submission has already been loaded into memory for the email composition process — meaning that even though the value is in the DB, RSForm’s email system is unaware of it by the time it parses the {estimate_id} tag. Try this version using RSFormProHelper::addFieldToSubmission() to update RSForm’s internal in-memory representation of the submission values, so when the email is parsed before it’s sent, the {estimate_id} token has ( I hope) a value associated with it.
    <?php
    // Path for log file
    $log_path = JPATH_SITE . '/administrator/logs/quote_email_debug.log';
     
    // -- 1. Start logging
    file_put_contents($log_path,
        "[" . date('c') . "] EMAIL SCRIPT STARTED.\n",
        FILE_APPEND
    );
     
    // -- 2. Get Submission ID
    $submission_id = isset($SubmissionId) ? (int) $SubmissionId : 0;
     
    // -- 3. Check we have a submission ID
    if ($submission_id > 0) {
        // -- 4. Generate Estimate ID
        $estimate_id = 'EST-' . date('Y') . '-' . (10000 + $submission_id);
     
        // -- 5. Add to RSForm submission memory object (makes it available in email placeholders)
        RSFormProHelper::addFieldToSubmission($submission_id, 'estimate_id', $estimate_id);
     
        // -- 6. Log generated Estimate ID
        file_put_contents($log_path,
            "[" . date('c') . "] Estimate ID generated: $estimate_id | Submission ID: $submission_id\n",
            FILE_APPEND
        );
     
        // -- 7. Save Estimate ID to database (so it persists in submission records)
        try {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true)
                ->update($db->quoteName('#__rsform_submission_values'))
                ->set($db->quoteName('FieldValue') . ' = ' . $db->quote($estimate_id))
                ->where($db->quoteName('SubmissionId') . ' = ' . $db->quote($submission_id))
                ->where($db->quoteName('FieldName') . ' = ' . $db->quote('estimate_id'));
            $db->setQuery($query);
            $db->execute();
     
            file_put_contents($log_path,
                "[" . date('c') . "] Estimate ID successfully saved to database.\n",
                FILE_APPEND
            );
     
        } catch (Exception $e) {
            file_put_contents($log_path,
                "[" . date('c') . "] ERROR saving Estimate ID to database: " . $e->getMessage() . "\n",
                FILE_APPEND
            );
        }
     
    } else {
        // -- 8. Log missing submission ID
        file_put_contents($log_path,
            "[" . date('c') . "] ERROR: No Submission ID found.\n",
            FILE_APPEND
        );
    }
    ?>

    Then if i'm right using this in the email template should work.
    <p><strong>Estimate ID:</strong> {estimate_id:value}</p>
    If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
    The administrator has disabled public write access.

    Custom Variables and Conditional Email Responses 2 weeks 4 days ago #44019

    • greg20
    • greg20's Avatar
    • OFFLINE
    • Fresh Boarder
    • Posts: 3
    You are exactly correct. The Estimate ID is being generated after the form is loaded into memory because I need the submission ID which is not available until the form is submitted. I'm running RSForm Pro version 3.3.16. I tried your fix and received the message:
    Warning
    Call to undefined method RSFormProHelper::addFieldToSubmission()

    I fixed the other problem by replacing {else} with nested if statements. I'd really like to get this to work and I want to thank you for your reply! Any other suggestions?
    The administrator has disabled public write access.

    Custom Variables and Conditional Email Responses 6 days 2 hours ago #44023

    • iceferret
    • iceferret's Avatar
    • OFFLINE
    • Gold Boarder
    • Posts: 250
    • Thank you received: 65
    Still playing with this in spare time, thought I had a solution but no.
    If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
    Last Edit: 5 days 21 hours ago by iceferret.
    The administrator has disabled public write access.

    Custom Variables and Conditional Email Responses 5 days 10 hours ago #44024

    • greg20
    • greg20's Avatar
    • OFFLINE
    • Fresh Boarder
    • Posts: 3
    thanks. I was so hopeful that would have worked! I'm not sure what version you are using, but if that method would be available it would be awesome! I've tried everything I know even using chatgpt and it just doesn't work and my website conversion is at a standstill. I just don't know the backend well enough to figure this out. I submitted a support ticket but "they don't support custom coding" so no help at all.
    The administrator has disabled public write access.

    Custom Variables and Conditional Email Responses 5 days 4 hours ago #44026

    • iceferret
    • iceferret's Avatar
    • OFFLINE
    • Gold Boarder
    • Posts: 250
    • Thank you received: 65
    Is it absolutely required that you use the submission Id or do you just need a unique and auto incremented estimate id. Have you access to the database to add a column holding a number i.e: 1000?
    Asking because i coded an auto incremeting membership number for a club which could be adapted very easily, basically

    retrieve number from database on form load - assign to hidden field1
    increment number and assign to another hidden field2 mapped to database
    on form submit - do whatever using number and assign result to a hidden field3

    This means that to get the estimate id into your email (or pdf)you just need {hidden field3:value} as everything is done before they are sent
    If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
    Last Edit: 4 days 3 hours ago by iceferret.
    The administrator has disabled public write access.
    • 1

    Read this first!

    We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

    However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

    For more information, the Support Policy is located here.

    Thank you!