PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Validation problem with custom field

  1. Hello there,

    I added a new field using gform_field_input. This field output a facebook LIKE box.

    Everything works fine until the validation.

    The LIKE box disappear and I would like it to stay on the page.

    Could you please advice me on how I could fix this problem ?

    Here is my code for adding the new field :

    add_action("gform_field_input", "facebooklike_input", 10, 5);
    
    function facebooklike_input($input, $field, $value, $lead_id, $form_id){
    
    if($field["type"] == "facebook-like"){
    
    $input = '';
    
    if (sfc_is_fan()) { // Function developed by Simple Facebook Connect by Otto.
    
    $input .= 'You LIKE us on Facebook, your chances are doubled.';
    
    } else {
    
    $input .= 'To double your chance to win, LIKE us on Facebook.';
    
    }	
    
    } 
    
    return $input;
    
    }
    
    add_filter("gform_add_field_buttons", "add_facebooklike_field");
    
    function add_facebooklike_field($field_groups){
    
    foreach($field_groups as $group){
    
    if($group["name"] == "advanced_fields"){
    
    $group["fields"][] = array("class"=>"button", "value" => "Facebook Like it !", "onclick" => "StartAddField('facebook-like');");
    
    break;
    
    }
    
    }
    
    return $field_groups;
    
    }
    Posted 12 years ago on Monday November 14, 2011 | Permalink
  2. Any one with an idea on how I could fix that ?

    Thanks.

    Posted 12 years ago on Tuesday November 15, 2011 | Permalink
  3. There was a small problem with your code when displaying the button in the admin. Following is the code with the fix:
    http://pastie.org/2869312
    As far as the field disappearing after validation, I could not replicate it. Following is a screenshot of my form after failing validation. Note the text from your field is still there.
    http://grab.by/bfge

    Did I misunderstand the issue?

    Posted 12 years ago on Tuesday November 15, 2011 | Permalink
  4. Hi Alex,

    Thanks for your answer !

    In fact, my custom field will display a Facebook Like Box like here :

    http://www.tkwk.be/client/acea/www/contest-of-the-month/

    My code for the custom field : http://pastie.org/2871065

    The only problem is that after validation it seems that the Facebook Like Box which was containing an iFrame is now empty... I would like to understand why and find a way of fixing this issue.

    Your support is much appreciated.

    Cheers.

    Posted 12 years ago on Wednesday November 16, 2011 | Permalink
  5. Update :

    When I use HTML5 / JS integration it doesn't work :

    [php]
    $input = '<div class="fb-like-box" data-href="http://www.facebook.com/pages/Our-Future-Mobility-Now/172720562818982" data-width="292" data-height="150" data-show-faces="false" data-stream="false" data-header="false"></div>';

    But when I use pure iframe the validation process does not remove the like box :

    [php]
    $input = '<iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FOur-Future-Mobility-Now%2F172720562818982&width=292&height=62&colorscheme=light&show_faces=false&border_color&stream=false&header=false&appId=215129495225503" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:62px;" allowTransparency="true"></iframe>';

    Any idea why ?

    Thanks again for the support.

    Posted 12 years ago on Wednesday November 16, 2011 | Permalink
  6. It looks like the problem is related to AJAX being enabled in your form. When AJAX is enabled, some scripts may need to be re-initialized when the page is submitted. The HTML5/javascript integration probably falls under that scenario.
    What I recommend you do is simply disable AJAX for your form.

    Posted 12 years ago on Wednesday November 16, 2011 | Permalink
  7. Hi Alex,

    Me again ! Thanks again for the Pastie, it really helped me out.

    I have still a question regarding this :

    In the original pastie (http://pastie.org/2906268) the first $input variable is empty !

    I can click my button "Facebook Like It !" in the admin and the custom field is displayed.

    If I change the value of my $input into something like this : http://pastie.org/2906281

    The button "Facebook Like It !" in the admin doesn't work anymore.

    Do you have any idea why ?

    If I need to use it, I have to add the field with the value $input = ''; in my code then change the value of $input once the field is already into the form.

    Thanks again for your time and patience.

    J.

    Posted 12 years ago on Wednesday November 23, 2011 | Permalink
  8. Any ideas ? I tried to find out what wasn't good in my code but I can't...

    Any help would be much appreciated.

    Posted 12 years ago on Saturday November 26, 2011 | Permalink