Forms Field CAPTCHA

edited December 2016 in Bug Reports
The documentation for the Forms module is absolutely wrong for how to manually echo the CATPCHA.

The docs say

"Special Hidden Fields

If you are using your own HTML code, you may need to include 2 additional hidden fields with values—return_url and form_url. There is also an "__antispam__" field that automatically gets generated and can be outputted automatically. Below is an example of what you can include in your own blocks.
...


<?=$__antispam___field?>
"

It took us far longer than it should have to solve this. First there's the '"__antispam__" field' part. So we thought it was a variable of __antispam__ then we noticed $__antispam___field has three underscores between antispam and field. So we tried with three underscores. We tried with 'field', without 'field' both with two and three underscores. Finally we found and looped the $fields variable that has '__antispam__' to then find out it had a property 'field'.

<?php echo $fields['__antispam__']['field']; ?>

Fix your documentation please.

Comments

  • edited 3:14PM
    I'm sorry but I'm not sure if I'm seeing the same issue on my end. The following variable if outputted in your view file should return the code for the anti spam method. I just tested it by adding the following to the fuel/application/config/forms.php config file for a particular form configuration:
    .... 'anti_spam_method' => array('method' => 'recaptcha', 'recaptcha_public_key' => 'xxx', 'recaptcha_private_key' => 'xxx', 'theme' => 'white'), 'block_view' => 'forms/contact-form', ...

    Then in the form's associated view file that in my case was located in 'fuel/application/views/_blocks/forms/contact-form', the following was added which outputted the reCaptcha HTML (and it included the 3 underscores):
    <?=$__antispam___field?>
  • edited December 2016
    "Customizing the HTML

    There are several ways to generate the HTML for the form. The first option is to use "auto" which will use the Form_builder class to generate the form based on the fields you've specified. Fields can be specified in the CMS or passed in under the 'fields' parameter as demonstrated in the above example. The second option is to use a block view and the third is to simply use an HTML string. In both cases, you will automatically have several variables passed to it included a $fields array which contains an array of all the the rendered fields, their labels, and their "key" values."

    We didn't set anything in the config file, set the block view through the CMS and told it to use reCAPTCHA. We have a static block with all of the HTML already in the view. We don't rely on the form generated fields because our client wants a very specific layout, so we can't just loop through and create a linear page. When we tried adding the captcha at the end through the variable listed above that variable did not exist. It took some looking to find that it was in in the $fields array mentioned in the 'Customizing the HTML' section.
  • edited 3:14PM
    The block view should be getting both a $fields array as well as a variables with the field's name and a "_field" as a suffix (thus the 3 underscores for the $__antispam___field because the suffix starts with an underscore). The reason for both is for those situations where you don't want to loop through the array and just want access to the rendered field as a variable. There is also an associated "_label" suffix if you want to access the field's rendered label directly. The fuel/application/modules/forms/libraries/Fuel_forms.php file has a Fuel_form::rendered_vars method which preps those variables and is called in the Fuel_form::render() method if you want to test further to see what may be going on.
  • edited December 2016
    Those variables do not exist; __antispam___field is null as well as other fields that are suppose to have variables. We already tried that, but again they are null, however, the fields exists within $fields array.

    To note, we dumped all the defined variables to the page and none of the fields were in the dump.
  • edited 3:14PM
    Would you mind debugging the Fuel_form::render() and Fuel_form::render_vars() method (which is used by the Fuel_form::render()) to see what variables are getting set?
Sign In or Register to comment.