Forum Replies Created

Viewing 15 replies - 1 through 15 (of 30 total)
  • Plugin Author Irvin Lim

    (@irvinlim)

    Thanks for your contribution too! ??

    Plugin Author Irvin Lim

    (@irvinlim)

    Implemented in 1.3.0.

    Plugin Author Irvin Lim

    (@irvinlim)

    Sorry, I realised that the method using Location Rules above should not be used, as bots can bypass the form. This is noted in my README: https://github.com/irvinlim/acf-recaptcha#field-group-setting

    You should go ahead with your custom plugin method instead. If you do publish the plugin on the WordPress Plugins repository, do reply with a link to your plugin, in case it may help other users in the future.

    I’m closing this topic as resolved, since you have found a solution.

    • This reply was modified 7 years, 3 months ago by Irvin Lim.
    Plugin Author Irvin Lim

    (@irvinlim)

    Actually, what I meant was to have these two field groups, added to your page using location rules:

    acf_add_local_field_group(array (
      'key' => 'group_recaptcha',
      'title' => 'Field group for non-logged in',
      'fields' => array (
        array (
          'key' => 'field_recaptcha',
          'label' => 'reCAPTCHA',
          'name' => 'recaptcha',
          'type' => 'recaptcha',
          'site_key' => '',
          'secret_key' => '',
        ),
      ),
      'menu_order' => 0,
      'position' => 'normal',
      'style' => 'default',
      'label_placement' => 'top',
      'instruction_placement' => 'label',
      'hide_on_screen' => '',
      'active' => 1,
      'description' => '',
      'recaptcha' => true,
      'location' => array (
        array (
          array (
            'param' => 'current_user',
            'operator' => '!=',
            'value' => 'logged_in',
          ),
          array (
            'param' => 'page_template',
            'operator' => '==',
            'value' => 'my-page-template.php',
          )
        )
      )
    ));
    
    acf_add_local_field_group(array (
      'key' => 'group_other_fields',
      'title' => 'Field group for all users',
      'fields' => array (
        array (
          'key' => 'field_text',
          'label' => 'Text Field',
          'name' => 'text_field',
          'type' => 'text',
        ),
      ),
      'menu_order' => 1,
      'position' => 'normal',
      'style' => 'default',
      'label_placement' => 'top',
      'instruction_placement' => 'label',
      'hide_on_screen' => '',
      'active' => 1,
      'description' => '',
      'location' => array (
        array (
          array (
            'param' => 'page_template',
            'operator' => '==',
            'value' => 'my-page-template.php',
          )
        )
      )
    ));

    This works, and you can do this in the UI as well. The only caveat is that you don’t explicitly pass the field group ID when calling acf_form(), but rather, you use location rules to specify where they should appear instead.

    In the end, I wrote a quick plugin that adds some field settings to any field

    This is also a good solution – I agree this could make up for the missing functionality in ACF itself. In fact I think this is a better solution than trying to hack around both the ACF core and ACF reCAPTCHA plugins.

    • This reply was modified 7 years, 3 months ago by Irvin Lim.
    Plugin Author Irvin Lim

    (@irvinlim)

    I’m sorry, I didn’t get what you meant by the Clone field… Does it work if you have separate field groups?

    I’m not familiar with Advanced Forms either, sorry. Is the exclude argument part of the acf_form() API? Perhaps if you showed me some of your code used to add your form to your template I could get a better understanding.

    One more way I can think of is to make use of ACF hooks to remove any reCAPTCHA fields when the user is logged in, as such:

    function remove_acf_recaptcha_if_logged_in($field) {
        if (is_user_logged_in()) {
            return null;
        }
    
        return $field;
    }
    
    add_action( 'acf/load_field/type=recaptcha', 'remove_acf_recaptcha_if_logged_in', 10, 1 );

    And you will have to disable ACF reCAPTCHA Protection as well in your form:

    acf_form(array(
        ...
        'recaptcha' => !is_user_logged_in(),
    ))
    • This reply was modified 7 years, 3 months ago by Irvin Lim.
    • This reply was modified 7 years, 3 months ago by Irvin Lim.
    Plugin Author Irvin Lim

    (@irvinlim)

    Sure, that sounds good!

    Do you think you can create a PR for this on GitHub? I’ll try to look into it over the next few days, but I’ll be away from next week so if you need it urgently I can just merge in the PR once you’re done.

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi,

    I see what you mean. I was actually thinking of creating a field group with a single reCAPTCHA field, with the location rule for being not logged in, and putting the rest of your fields in a separate field group. You can actually put multiple field groups in one form, and they will all be validated together.

    However, I just tried it and found out that when you use acf_form() with field_groups, it doesn’t obey location rules set on the field group. You can still use the UI (or do it programmatically with acf_add_local_field_group) to add field groups and insert the field groups into the correct page using location rules. Just make sure you set a different Order No. for the two field groups.

    I’m not sure if this will still work for your use case.

    And yes, please open a PR on GitHub if you wish! I can take a look and consider incorporating this into acf-recaptcha. However, I am still strongly in favour of leaving this up to ACF location rules since it’s already included – if we do include this within acf-recaptcha, it’s kind of a slippery slope for feature bloat in the future.

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi,

    That’s a great idea for a use case, but I think that such functionality should be left up to the ACF framework itself.

    However, you can make use of ACF’s Location Rules under the field group to only display a particular field group if a user is not logged in. Otherwise, if you are adding the field programmatically, it should be simple enough to do so using some custom PHP code.

    Do give this a try and let me know if it works for you. Thank you!

    Plugin Author Irvin Lim

    (@irvinlim)

    Sorry to hear it didn’t work out for you. ??

    Anyhow, glad that you fixed all the problems in the end!

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi, really sorry for replying to this so late.

    I noticed for the first example you gave, you used 'recaptcha' => 'true' instead of 'recaptcha' => true – which might be one source of the problem. I will be allowing the string as well, which will be released in the next patch.

    I might also need more details about the field group in the first code example. I’m unable to reproduce any of such issues where you post is empty – perhaps it’s because you set post_title and post_content to false, that’s why you’re not seeing any content in the editor? Are your custom fields values being set?

    If the AJAX validation didn’t work in the second example, and instead you’re seeing a wp_die() screen, it’s probably because something is calling wp_die() in the validate_value hook for one of your fields, or there might be a JavaScript error.

    Hope that I wasn’t too late to help!

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi there, sorry to hear that you’re having trouble.

    Could I take a look at how you’re creating the form with acf_form()? If you are not using field groups, then I suppose you are using acf_add_local_field() to register your fields?

    Plugin Author Irvin Lim

    (@irvinlim)

    You’re very welcome, thanks for the review! ??

    Plugin Author Irvin Lim

    (@irvinlim)

    Thank you! ?? Means a lot to me, I appreciate it!

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi, due to lack of activity I will be closing this thread.

    If you still require assistance, do open a new support thread. Thank you!

    Plugin Author Irvin Lim

    (@irvinlim)

    Hi, due to lack of activity I will be closing this thread. If you have any other queries do open a new support thread. Thank you!

Viewing 15 replies - 1 through 15 (of 30 total)