WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Report dynamically (jquery) added fields in the email? (7 posts)

  1. gillespieza
    Member
    Posted 3 years ago #

    Thanks for such a brilliant contact form plugin. I have created a form that needed extra fields to be dynamically added by the user.

    Use-case: The user needs to add authors, and I have no way of knowing how many authors will be needed. Rather than adding extra fields that might not be necessary for some users and might not be enough for other users, I have a little jQuery script that clones my div with the author information and also auto-increments the input (and span) field names/ids. So

    <span class="wpcf7-form-control-wrap author1">
       <input type="text" name="author1" value="" class="wpcf7-text
       wpcf7-use-title-as-watermark textInput watermark" size="40"
       title="Author">
    </span>

    is cloned as

    <span class="wpcf7-form-control-wrap author2">
       <input type="text" name="author2" value="" class="wpcf7-text
       wpcf7-use-title-as-watermark textInput watermark" size="40"
       title="Author">
    </span>

    It works perfectly, except I don't know how to get these new, dynamically-added fields to be reported in the email that "contact form 7" sends on successful submit of the form.

    Please help? Is there something I could add to the on_sent_ok hook or some other hook or something? If I can figure out this last part, I'd love to release this as an add-on module to Contact Form 7, since I didn't find any plugins to add extra fields by jQuery.

  2. thetrickster
    Member
    Posted 3 years ago #

    I have the same problem and am looking for answers. I've been searching this forum for answers all day and cannot find one. I'm subscribing via email to this thread. Anyone have any ideas?

  3. WereAllThieves
    Member
    Posted 2 years ago #

    Has anyone been able to get this functionality to work?

    Adding fields dynamically to a form would be a huge improvement to this contact form script. I've been wanting to do this with several projects and so far haven't been able to figure it out. A similar add-on to Fast Secure Contact Form would also be great.

  4. Naoise Golden Santos
    Member
    Posted 2 years ago #

    same here with PHP generated content

  5. thetrickster
    Member
    Posted 2 years ago #

    I ended up using this plugin http://wordpress.org/extend/plugins/contact-form-7-dynamic-text-extension/ and switched from javascript cookies to PHP GET variables and I was all set.

  6. legna70s
    Member
    Posted 2 years ago #

    ok, can someone please speak english instead of code. LOL I am attempting something similar to gillespieza in that I want the user to be able to add names to the CF7 and I have already installed the DTE to use with it. I have ready post upon post and articles all over google, but I do not know enough about coding to know "WHAT" needs to be written for a short code, or anything from step A to step Z. I need some help with this and a step by step tutorial for dummies. beginning with HOW to write the code and where to place it versus how to write the short code correctly into the CF7 FORM and MESSAGE BODY. Is there something out there like that?

  7. thetrickster
    Member
    Posted 2 years ago #

    Here's a basic step-by-step:

    1. Make sure you have <b>both</b> Contact Form 7 and Contact Form 7 Dynamic Text Extension installed as plugins and activated on your WordPress site.
    2. Create a default Contact Form with the Contact Form 7 plugin
    3. For example purposes, let's say we want to grab an Author's name and automatically input it into the form...
    4. Insert the following code into your Contact Form 7 form where it is the form layout:
      <p><label>Author</label>
      [dynamictext myauthor "CF7_GET key='myauthor'"]</p>
      
    5. If you want to grab some other type of data from dynamically, change wherever it says "author" in the code above to "name" or whatever name for the data you want to input dynamically
    6. Now in the section where it says "Mail" on Contact Form 7 we can add to the email that gets sent out. Let's add this HTML code to our email layout wherever you feel fit:
      [myauthor]
      . That is a shortcode. Shortcodes are used within WordPress and you can tell it's a shortcode because the code is inside of brackets ( [ and ] ). When we created our form field above with the other shortcode we called our dynamictext box "myauthor" so when we are printing it in the Email layout, we just need to use that unique identifier in brackets to put it in the email.
    7. Save your form
    8. Place your form on a page or in a post on your wordpress website
    9. Visit the contact form we just created on your website
    10. In the URL of your browser window add onto the URL with the following text:
      ?myauthor=Mark Twain

      and hit ENTER or GO to visit that URL with the new parameter we added to the URL

    11. Your form should have "Mark Twain" added to the authorname field automatically

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic