• Hi.
    For design reasons i have to put the field descriptions (Your Name, Your Mail etc.) inside the fields with values.
    Then i included some JS into the plugin.php where the html output is generated, to kill the value on focus. To that point –?everything works fine.

    But now validation for standard required textfields does not work properly since it only checks if there’s an value. And because there are values by default –?no error message pops out. Know what i mean?

    Can someone provide me with the code to fix that?
    It’s unfortunately far beyond my php knowledge.

    ??

    Btw. This would be a very nice feature for future versions. I think many people would enjoy to have that option.

    Thanks and bests,
    m.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter soundofsirens

    (@soundofsirens)

    Nobody ever had the same idea? Really? ??

    I’m wanting to get the fields to clear onFocus as well… is there a simple way to make this happen?

    I edited \modules\text.php

    and replaced

    $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';

    with

    $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' onfocus="if(this.value==\'';
    
    $html = $html . esc_attr( $value ) . '\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'' . esc_attr( $value ) . '\';" />';

    You’ll have to do something similar for the other fields (textarea, etc.).

    What I am still trying to fix is validating these fields.
    Now that there they have default text in them, and if they are “required” fields, that default text lets them pass validation.

    10x shrenno!

    Hi,

    Go to modules/text.php line 110 and add after $name = $tag['name'] the following lines :

    $values = (array) $tag['values'];
    
        // Value
        if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) {
            if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['ok'] )
                $value = '';
            else
                $value = stripslashes_deep( $_POST[$name] );
        } else {
            $value = isset( $values[0] ) ? $values[0] : '';
        }
    
        if($_POST[$name] == $values[0]) $_POST[$name]= '';

    Good luck.

    Thanks vladvornicu. Now why can’t the developers of Contact Form 7 add those lines of code to the plugin? The only problem with doing it ourselves is that we lose this on upgrades…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Contact Form 7] erase fields onFocus > validation problems’ is closed to new replies.