Ali Khallad
Forum Replies Created
-
Hello @treylok
Since email field is a compound field ( consisting of more than one input ), it has a different rendering approach. In this case, we can use another hook that allows filtering all types of fields.
The following code should fix both problems for you
add_filter('mf_input_args', 'mf_custom_input_attributes', 10, 1);
function mf_custom_input_attributes($args) {
$traget_form_id = 81;
if ( !isset($args['attributes']['name']) || strpos($args['attributes']['name'], "mform_{$traget_form_id}_mfield_") !== 0 ) {
return $$args;
}
$prefix = "mform_{$traget_form_id}_mfield_";
$email_field_id = 7;
$email_suffix = $email_field_id . '[email]';
$confirm_email_suffix = $email_field_id . '[email_confirmation]';
switch ($args['attributes']['name']) {
case "{$prefix}{$email_field_id}":
$args['attributes']['id'] = $prefix . $email_field_id . '_email';
$args['content'] = str_replace('for="' . $prefix . $email_suffix . '"', 'for="' . $prefix . $email_field_id . '_email"', $args['content']);
$args['content'] = str_replace('for="' . $prefix . $confirm_email_suffix . '"', 'for="' . $prefix . $email_field_id . '_email_confirmation"', $args['content']);
break;
case "{$prefix}{$email_suffix}":
$args['content'] = str_replace('/>', ' autocomplete="email" id="' . $prefix . $email_field_id . '_email"/>', $args['content']);
$args['attributes']['id'] = $prefix . $email_field_id . '_email';
break;
case "{$prefix}{$confirm_email_suffix}":
$args['content'] = str_replace('/>', ' autocomplete="off" id="' . $prefix . $email_field_id . '_email_confirmation"/>', $args['content']);
$args['attributes']['id'] = $prefix . $email_field_id . '_email_confirmation';
break;
default:
break;
}
return $args;
}Make sure to change the form ID and the field ID and it will work as expected.
Note that the [email] part is autogenerated for compound fields, so it is intended.Hey @treylok
This can be achieved with a custom snippet for the time being until we add this feature.
Place this snippet in your child theme’s functions.php file and modify the IDs accordingly.add_filter('mf_field_display_args', 'mf_custom_field_display_attributes', 10, 1);
function mf_custom_field_display_attributes($params) {
$traget_form_id = 80;
if ( strpos($params['id'], "mform_{$traget_form_id}_mfield_") !== 0 ) {
return $params;
}
$prefix = "mform_{$traget_form_id}_mfield_";
$firstname_field_id = 1;
$lastname_field_id = 2;
$email_field_id = 3;
switch ($params['id']) {
case "{$prefix}{$firstname_field_id}":
$params['attributes']['autocomplete'] = 'given-name';
break;
case "{$prefix}{$lastname_field_id}":
$params['attributes']['autocomplete'] = 'family-name';
break;
case "{$prefix}{$email_field_id}":
$params['attributes']['autocomplete'] = 'off';
break;
default:
break;
}
return $params;
}Let me know if you have any additional questions.
It can be cleaner than this, but the quickest way to do it without a lot of work is:
Step 1:?Store all emails inside an option as an array. Let’s name the option “mf_custom_email_list”, make sure it’s not autoloaded and each email has an ID as key. ( make sure the data is saved as a serialized php array ), it’s better to update using WordPress core functions, eg:update_option('mf_custom_email_list', array(
'1' => '[email protected]',
'22' => '[email protected]',
'3' => '[email protected]'
), 'no');Step 2: Update all the mailto links to redirect to a contact page but make sure to add a query param to reflect the email ID, it can be “to” for example, so the url will look something like <a href=”https://yourwebsite.com/contact?to=22″>.
Step 3:?Install?Mega Forms, create your contact form and add a hidden field, set the hidden field value to something like this
{mf:misc get="to"}
as it appears in the screenshot. Then under actions tab, add an “email” action and set the “to” field to pull the email from the hidden field you created, it will look something like this{mf:fields 6}
where number 6 is the ID of the field. See the attached screenshot for examples.Step 4:?Now add a snippet that will replace the provided ID with the actual email server side to make sure emails are not exposed anywhere. Here is the snippet you can use
add_filter('mf_posted_data_before_process', 'mf_modify_email_field', 10, 3);
function mf_modify_email_field($posted, $form, $context) {
$the_hidden_field_id = 6;
// Check if the field with ID 6 exists in the posted data
if (isset($posted['fields'][$the_hidden_field_id])) {
// Get the submitted value
$submitted_value = mfpost($the_hidden_field_id, $posted['fields']);
// Get the custom email list from WordPress options
$custom_email_list = get_option('mf_custom_email_list', array());
// Not valid data format, initialize an empty array
if (!is_array($custom_email_list)) {
$custom_email_list = array();
error_log("mf_custom_email_list option is neither an array nor a valid serialized array.");
}
// Check if the submitted value exists as a key in the custom email list
if (isset($custom_email_list[$submitted_value])) {
// Replace the submitted value with the corresponding email
$posted['fields'][$the_hidden_field_id] = $custom_email_list[$submitted_value];
} else {
// If the key doesn't exist, you might want to handle this case
// For example, you could set a default email or log an error
error_log("No email found for key: " . $submitted_value);
// Optionally set a default email:
// $posted['fields'][$the_hidden_field_id] = '[email protected]';
}
}
return $posted;
}Awesome, good to hear you got it sorted.
Hello,
Please use the shortcode widget from elementor to add the form. Each form has a shortcode that you can find in the list of forms on the right side.
Let me know if that solves your problem!
Forum: Plugins
In reply to: [Plugin Check (PCP)] Not working for any plugin (Windows)Same here, I get this for every plugin ( Even hello dolly can’t pass):
- Failed check_against_phpcs.
- Failed check_against_phpcs_review.
I ran it on a website using LAMP stack.
That’s great, good to hear you were able to fix this issue.
Feel free to open another ticket if you need help with anything else.
Hello Andrew,
May I ask how did you add the shortcode to the footer? was it via a file, or somewhere in the customizer?
Customizer fields don’t usually support shortcodes, but if you use a widget to add it, it should work without a problem.
Just let me know, how it’s being used now and I can help you make it work, should be a simple problem to solve.
Good to hear it’s resolved now. The reason it’s not working with the page builder is because the order id is not passed in the URL, so the only way is to pass the order id using PHP.
Hey, I just released an update, can you install version 1.0.5 and try the PHP code again.
It doesn’t work by default with the shortcode because the order ID is not supplied in the URL, so you have to supply the ID from the shortcode. You have already tried this but it didn’t work due to a bug, which we fixed and it should be good now.
Hello,
Can you share a little more details about the issue. What’s the checkout path, how did you create it and where did you place the shortcode? Also, can you share the shortcode you used so I can check?
Thanks,
Ali
Hello, I’ve made some changes in the current version to change the “.right” and “.left” properties. To use the changes you’ll need to update the plugin manually by deleting it and re-installing it.
Regarding loading assets only when the shortcode is available, this is not possible because when you call assets conditionally to the shortcode they get loaded in the footer. This causes the forms to look broken until the page is fully loaded, so it’s important to load the CSS in the header. However, we do this with JavaScript since it’s not required upfront and we can wait for it until the page is loaded.
Please test and let me know if you’re still having issues.
Thanks,
AliHello,
Initially we have created two version of Mega Forms, the normal one and the pro one, later we merged them together and the second stylesheet is for the pro version, it doesn’t have any duplicate items/code or anything.The pro version is also there to show developers how to extend the plugin, it’s build seperately with new features and added under /pro folder.
Now regarding your problem, could you specify what is broken exactly and how can we replicate? this way we might be able to provide better support.
That’s great, let us know if you need anything else ??
The “mf_process_entry_actions” should provide everything you need.
It’s created like this:
do_action('mf_process_entry_actions', $entry_id, $entry_meta, $this->form, $this->submission_values);
As you see, it holds the entry id, entry meta, the form object, and the submission values. If you need more info, there are functions to pull extra data from entry and form.