WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Textbox Array (5 posts)

  1. Justin Korn
    Member
    Posted 3 years ago #

    I realize I am trying to something a bit unique, but was hoping there might be an answer.

    I am creating a form where users will be able to add more text fields as they need them available. So, they are filling out a list of cities they want to visit, I start them off with 3, but if they want to add more, I provide a button with a little javascript and add a new field. Normally, to do this, I'd create each text field with an array attribute ie. name=city[] and on submit, loop through the array. Unfortunately, I can't natively do this within Contact Form 7. Perhaps there is a way to create a custom type, but without development documentation on the plugin, I wasn't sure exactly what I was doing.

    Any advice?

    Thanks!

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Justin Korn
    Member
    Posted 3 years ago #

    I figured out how to create a custom field TextArray, however, the email comes through with the value 'Array' instead of the actual values in the array.

    If anyone can point me to were this is handled in the plugin so I can possibly extract the values properly, I'd really appreciate it.

    If I find it, I'll post it, but still struggling at the moment.

    Thanks!

  3. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    The array of textarea values is cast to a string, so you see the 'Array' string value. The casting to string is processed in wpcf7_textarea_validation_filter() in modules/textarea.php. You can comment out the lines or remove the filters if you don't want it.

  4. mrmcq
    Member
    Posted 3 years ago #

    Takayuki...you are fantastic! I've been searching for a resolution to this issue for months! Thanks for covering this issue, I've been utilizing a jQuery field duplicator but couldn't for the life of me figure out how to pass text field values ("Array" issue).

    Thanks so much, now I just have to figure out how to loop them to come out in proper order with the other passing fields. I appreciate your tip!

  5. maurice-wingfield
    Member
    Posted 3 years ago #

    mrmcq, I couldn't get the jQuery plugin you're describing to work and in the end just wrote my own. It took a couple days, but the user can now create and delete new fieldsets on the fly. I haven't gotten as far as getting the "Array" issue you describe. I would really appreciate it if you could give me some guidance on how the form fields can be coded in such a way for CF7 to recognize it once the form's been submitted.

    For example, the CF7 form would look like this:

    1. CF7 shortcodes
    [text first_name]
    [submit]

    2. CF7 generates the html form
    <form action="#" method="post" class="#">
    <input type="text" name="first_name">
    <input type="submit">
    </form>

    3. Then the search_and_replace plugin would change the name of the text field
    <form action="#" method="post" class="#">
    <input type="text" name="first_name[]">
    <input type="submit">
    </form>

    4. The user dynamically adds another text field and submits the form
    <form action="#" method="post" class="#">
    <input type="text" name="first_name[]">
    <input type="text" name="first_name[]">
    <input type="submit">
    </form>

    5. CF7 has no shortcode for a field named first_name[] and can't process it.

    I would love any kind of insight you could provide.

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic