Thanks Victor. I just solved it by creating a shortcode. However, it is not working inside of a frm-stat shortcode - [frm-stats id=123 type=count 123="[456]@[user_email_domain]"]
For my project, I appended a category to an email address and used this as a filter. Using [email] worked fine. However, I realized that I'll have multiple people from the each company and the filter should apply to all people w/ the same domain. Hence, I created the shortcode below using ChatGPT (I'm not a developer). This shortcode isn't working the same way [email] worked. Are you able to see anything at first glance?
function get_user_email_domain() {
// Check if the user is logged in
if (is_user_logged_in()) {
// Get the current user's ID
$user_id = get_current_user_id();
// Get the user's email address
$user_email = get_userdata($user_id)->user_email;
// Extract and return the domain
list($user_name, $user_domain) = explode('@', $user_email);
return $user_domain;
}
return 'User not logged in';
}
function user_email_domain_shortcode() {
return get_user_email_domain();
}
add_shortcode('user_email_domain', 'user_email_domain_shortcode');
Thanks,
Chris
ChatGPT is notorious for not writing good code, especially anything specific to Formidable. As such, the code you posted retrieves the email from the WordPress user record, not a form field. THis means the user has to be registered and logged in. The code completely ignores Formidable data. If you need a developer's help, please see https://formidable-masterminds.com/developers-directory/
<p>The user must be logged in to view my forms. It produces the desired result - it displays the domain of the email address. However, it isn't working inside of the frm-stat. I believe [email] is also grabbing the user's email only if they are logged in, correct?</p><p>Also, I have entered this shortcode into a Text field where the domain is saved and appended with each form submission</p>
When a user fills out your registration form with the User Registration add-on enabled, you already have the user's email captured in the form data. At that point, it's a trivial task to separate the email ID and domain into separate hidden fields with jQuery/JavaScript that will work with frm-stats.
Your ChatGPT shortcode extracts the email from the WordPress user table. You can't count entries using frm-stat unless the data you want is in Formidable's data tables. The ChatGPT code is never going to work to accomplish your requirement. The design is wrong for Formidable. Please consult with a developer. ChatGPT is not a developer you can depend upon.
Thanks for your response. I apologize if there is some miscommunication here. I think I see the problem as you are trying to explain it to me. The timing of processing a shortcode w/in a FF shortcode is not lining up. Whenever the user submits a purchase form, the form captures his email address, and now it captures his domain as well. I was thinking "The data is in the table." However, to run the frm-stats shortcode, it now needs to run another shortcode inside of it. It will be easier if I first capture the user's domain separately upon registration and reference that field in the frm-stats shortcode instead of processing another shortcode within it. Am I on the right track? Thanks for your patience!
Exactly!
For anyone who needs the code ...
jQuery(document).ready(function($) {
var sourceField = '#field_wjqeu'; // Replace wjqeu with your source field key
var destinationField = '#field_iyhhr'; // Replace iyhhr with your destination field key
$(sourceField).on('input', function() {
var sourceValue = $(sourceField).val();
var atIndex = sourceValue.indexOf('@');
if (atIndex !== -1) {
var domain = sourceValue.substring(atIndex + 1);
$(destinationField).val(domain);
} else {
$(destinationField).val('');
}
});
});
Please login or Register to submit your answer