Check for Existing Emails in Database Before Submitting RSForm

Looking to add a line break in the placeholder text area of the RSform, but so far, no success. A form sample with the non-working text area can be found on the last page of the freelancer-form.
One solution is to explore the js and non-js options offered in this StackOverflow thread: https://stackoverflow.com/q/7312623/2943403. It is important to note that the non-js technique may have different outcomes on different browsers. For complete documentation on the jQuery Masked Input, visit http://digitalbush.com/projects/masked-input-plugin/.
If you prefer not to edit your index.php file, you can add the code to each form that requires Masked by navigating through Components >> RSForm >> Edit your form >> Tab Properties >> Tab Script and pasting the JavaScript code into the field without “—“.


Question:

My RSForm comprises of the subsequent fields:

  • Full Name
  • Email Address

Is it possible to utilize the

$_POST

script to verify whether or not the email address provided already exists in the database, as my intention is solely to gather new data?

As per the documentation of RSForms, it’s possible to achieve this task.

$_POST['form']['email_address']

I am uncertain about which coding language to utilize.


Solution:

To input the required information, go to the second textbox located in the
form properties
section and select the ”
PHP Scripts
” option.

$formId = 0; // CHANGE THIS VALUE to your form ID
$db = JFactory::getDbo();
$query = $db->getQuery();
$query
    ->select("*")
    ->from("__rsform_submission_values")
    ->where("FormId = " . $db->q($formId))
    ->where("FieldValue = " . $db->q($_POST['form']['email_address'] ));
$db->setQuery($query);
$db->execute();
$num_rows = $db->getNumRows();
// We found this email in the submissions
if ($num_rows > 0) {
    $invalid[] = RSresolveComponentName('email_address', $formId);
    echo RSshowForm($formId, $_POST['form'], $invalid);
}

To establish a new validation rule for the email_address field, you can include the function in the file validation.php located in components/com_rsform/controller/. Afterwards, you can choose “unique” as the Validation Rule by modifying the email_address field.

function unique($param, $extra=null)
{        
    $db = JFactory::getDBO();
    $param = $db->getEscaped($param);
    $db->setQuery("SELECT * FROM #__rsform_submission_values WHERE `FieldName`='email_address' AND `FieldValue`='".$param."'");
    $db->query();
    $invalid = $db->getNumRows();
    if ($invalid)
        return false;
    return true;
}

Additional information regarding custom validations can be found on this webpage: https://www.rsjoomla.com/support/documentation/rsform-pro/customizing-rsform-pro/custom-validation-rules.html.

Refer to this helpful thread at the RSJoomla forum, which discusses setting up a form that restricts each user to only one submission: https://www.rsjoomla.com/forum/37-rsform-pro/9162-setup-form-so-each-user-can-only-submit-once-.html

Frequently Asked Questions

Posted in Php