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.

Custom Form Field as HTML Field

  1. kristopherdesign
    Member

    My client requires multi-page forms with occasional instances of an audio recorder (javascript/Flash: https://github.com/jwagener/recorder.js). While I realize that I can create an HTML field to manually embed the necessary code, my goal is to create a Custom Form Field which would automate the process. In other words, create a button in the "Advanced Fields" section of the GF Admin labeled "Audio Recorder." When pressed, a new field would be created with the capabilities of an HTML field, and when this field is rendered on the front end a script would run to replace the content of this field with the necessary code to execute the audio recorder.
    Does this logic make sense? Am I taking the correct approach? I have followed the guidance offered here:
    http://wpsmith.net/2011/plugins/how-to-create-a-custom-form-field-in-gravity-forms-with-a-terms-of-service-form-field-example/
    to create the Custom Form Field, but I cannot get this new field to behave like an HTML field. Because it does not behave like an HTML field, GF is not handling the automated content creation correctly. In addition, I am also struggling to predefine the field's label as is done in a standard HTML field.

    Any help you can offer would be greatly appreciated. Thanks.

    Posted 11 years ago on Friday March 15, 2013 | Permalink
  2. What code are you using currently to create this field? Are you using the gform_field_advanced_settings filter: http://www.gravityhelp.com/documentation/page/Gform_field_advanced_settings

    Posted 11 years ago on Sunday March 17, 2013 | Permalink
  3. kristopherdesign
    Member

    No, I didn't touch the gform_field_advanced_settings filter because I wasn't concerned with adding any settings. My goal was to simply create a one-button solution that would allow me to swap the appropriate code in through the back end (via the gform_pre_render filter). I realize that I could do this using a css class assigned to a simple HTML field, but entering (and remembering) a css class is something I would like to avoid. Does that make sense?

    Posted 11 years ago on Monday March 18, 2013 | Permalink
  4. I'm afraid it does not. I'll ask some of the other support staff. But if you could provide screenshots or examples of what you're trying to do, that may help.

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink
  5. kristopherdesign
    Member

    Essentially, I have added my own Form Field ("Audio Recorder") through the gform_add_field_buttons filter. I understand how to make this field behave like a standard form field (ie, a text input field), but I do not understand how to make it behave like an HTML field. For my use, it appears essential that this custom field behave like an HTML field so that I can automatically swap in the necessary Audio Recorder HTML when the form is rendered. Here is a screen shot of the GF Admin: http://www.kristopherdesign.com/GF-Custom-Field2.png

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink
  6. Thank you for the screenshot. I'll ask the development team for their input on this one. In the meantime, can you please post the code you are currently using to create this field, at pastebin.com or pastie.org? Thank you.

    Posted 11 years ago on Thursday March 21, 2013 | Permalink
  7. kristopherdesign
    Member

    Here is the code as it currently stands (all in my functions.php file):
    http://pastebin.com/kpgZmEKx

    Through the gform_pre_render filter I have added I want to change the "content" of the field that I have created. I am aiming to treat this new form field as an HTML field so that GF will output the necessary code EXACTLY as I intend it (ie, as basic HTML field is handled by GF). I believe that this is the only approach available to me. Again, the problem I'm having is getting my new form field to behave like an HTML form field. I believe that the attribute I am aiming to add to my field is:
    "displayOnly":true
    I don't know how to do this. Nor am I certain that this is what needs to be done.

    Thanks.

    Posted 11 years ago on Thursday March 21, 2013 | Permalink
  8. There are a couple things you need to do:

    1) You will need to change his fieldSettings[] array (from your gform_editor_js hook) to match the one used by an HTML field. You can see that in the form.js file (towards the end of the file)

    2) You will need to do is change the contents of your gform_field_input hook so that it doesn't render an input field, but renders your HTML content instead. If you need to get rid of the field label when rendering the HTML content, you will need to use the gform_field_content hook instead of gform_field_input.

    Posted 11 years ago on Saturday March 23, 2013 | Permalink