WordPress.org

Forums

Contact Form 7
[resolved] dynamically update field value - wpcf7.3.3.3. (2 posts)

  1. acub
    Member
    Posted 1 year ago #

    Hello.
    the setup:
    WP version 3.4.2., very customized, almost impossible to update (very big website, thousands of users, theme not compatible higher)
    wpcf7 version 3.3.3. All working great, but...

    the problem:
    ...I'm dynamically building a string based on user interaction and passing the value to a form input. I'd like to make the field show the changes. Was able to put the string in the value using basic jQuery syntax, but the field still shows the title attribute instead of the value.
    Here's how the field's html looks before and after it gets the value:
    before:

    <span class="wpcf7-form-control-wrap text-621"><input type="text" name="text-621" value="" id="subiectul" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required wpcf7-use-title-as-watermark watermark" size="40" maxlength="200" title="Subiectul mesajului (max. 200 caractere)"></span>

    after:

    <span class="wpcf7-form-control-wrap text-621"><input type="text" name="text-621" value="Super Party, 13 octombrie 2013" id="subiectul" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required wpcf7-use-title-as-watermark watermark" size="40" maxlength="200" title="Subiectul mesajului (max. 200 caractere)"></span>

    What do I need to run/do in order to make the field show the value?

    Thank you for looking into this.

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

  2. acub
    Member
    Posted 1 year ago #

    I found the answer.
    For anyone wondering why their jQuery doesn't work, you need to enqueue the script in the footer, to the jquery array, so the wpcf7 scripts are loaded when yours is executed. Example:

    wp_enqueue_script('{your_script_name}','/{your_script_location}{your_file_name}.js', array('jquery') , null , true);

    And the actual jQuery for updating an input value:

    jQuery("#{your_field_id}").val('{your_value}').removeClass('watermark');

    Of course, you need to replace the accolades with your own specific values.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic