How To Verify Text Field with shortcodes in formidableform

By: Sina Pars | Asked: 04/21/2022
ForumsCategory: How-toHow To Verify Text Field with shortcodes in formidableform
Sina Pars asked 2 years ago

Hi every one,

According to your documentation, I want to validate the value of a field that is of text type and its default value is [email] before sending to prevent it from being changed using inspect tools, and for this I use the following code:

add_filter( 'frm_validate_field_entry', 'ff_keep_default_value', 10, 3 );
function ff_keep_default_value( $errors, $posted_field, $posted_value ) {
    $fields = array( 166, 168, 169 ); //change 166, 168, 169 to the IDs of the fields whose defaults you want to keep.  Include as many fields as you want.
    if ( in_array( $posted_field->id, $fields ) ) {
        $field_id      = $posted_field->id;
        $field         = FrmField::getOne( $field_id );
        $default_value = "";
        if ( $field && isset( $field->default_value ) ) {
            $default_value = $field->default_value;
        $default_value                   = do_shortcode( $default_value );
        $_POST['item_meta'][ $field_id ] = $default_value;

    return $errors;

But the problem is that instead of saving my original value (for example [email protected]) it comes and sends the shortcode [email] to its database./

Is there another way to do this?

2 Answers
Victor Font answered 2 years ago

I think the key to answering your question is in the snippet instructions :

"This code works with default values that are explicitly set (e.g. "100" or "gold") or that use standard WordPress shortcodes (i.e. a shortcode that works on a WordPress page). It won't work with special Formidable shortcodes, like [get param] or [date], that aren't standard WordPress shortcodes."

[email] is a special Formidable shortcode. It won't work with this snippet. To test shortcodes to see if they'll work with this snippet, create a post to render the shortcode. If you see the shortcode itself and not the expected output, it is a special shortcode that won't work with this snippet. If you see the expected output, the shortcode will work with this snippet.

There's probably another way to do this, but it depends on where the email value is stored in the first place. You need to explain what you want to accomplish with more detail. Is this a registration form? Is this a form that registered users fill in while logged in? What is the form for and are logged in users creating the entry?

If the users are not logged in, there's no way to tie an email address to a user apart from what they enter through the form. If they are logged in and you have the Formidable User Registration Add-on installed you can use the user meta shortcode to retrieve the logged in user's email address from the WordPress user record. However, the shortcode may not work with this snippet, in which case, you'd have to use the WordPress user functions to retrieve the default value.

Victor Font replied 2 years ago

One more thing, you can create your own shortcode to retrieve the details you want to preserve.

Sina Pars answered 2 years ago


Hi again

First of all, thank you for your complete answer

I have a survey form that contains various fields and users must log in to fill it out.

One of these fields is the user's e-mail, and because the user does not want to complete the e-mail, I defaulted on the [email] shortcode and left the field read-only so that the user could not change it.

But I'm worried that the user will change this value using Inspect element tools and enter another email. To prevent this, I want to make sure that the email sent to the server is the user's actual email, and if it is changed by Insect, show an error and Prevent sending

Sorry for the weak English


Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community