WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Contact Form 7] Feature Request - add onclick action (12 posts)

  1. megwoo
    Member
    Posted 4 years ago #

    Hi there,
    Love the functionality so far, but could you add an "onclick" action to the text field tag generation? I'm looking to add something like onclick="javascript:value='';" to the text fields so that the starting values disappear when clicked on.

    Thanks,
    Megan

  2. bencharity
    Member
    Posted 4 years ago #

    I second this! I would love that functionality! Also have a text color change. The pre-focus text a light grey, then on focus the typed text is dark grey or black.

  3. nachoplaza
    Member
    Posted 4 years ago #

    To get WAI-AAA validation, you have to include a default value in the inputs. You can do this now. But when you click on the input box, you have to delete the default value before writing anything. Some code will clear the value of the inputs boxes when you click them:

    <input type="text" id="author" name="author" value="Author" onfocus="if (this.value == 'Author') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Author';}" />

    It is like the search input on this page, on top rigth corner (Search WorPress.org). I second this too, with the pre-focus color on light grey.

  4. tomcat23
    Member
    Posted 4 years ago #

    I am going to try adding this into line 216 of includes/classes.php (version 1.10.1)

    $atts .= ' onfocus="if (this.value == \'' . esc_attr( $value ) . '\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'' . esc_attr( $value ) . '\';}"';

    This is tested and working.
    Cheers!

  5. tomcat23
    Member
    Posted 4 years ago #

    I believe the same line I just posted could be added to line 70 of modules/text.php in the new 2.0 version, but I'm not sure about the block of code above it. So I'd suggest using

    if ( $value != '' ) {
    	$atts .= ' onfocus="if (this.value == \'' . esc_attr( $value ) . '\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'' . esc_attr( $value ) . '\';}"';
    }
  6. neevai
    Member
    Posted 4 years ago #

    tomcat23 you're awesome! thanks so much!

  7. tomcat23
    Member
    Posted 4 years ago #

    I'm trying it below line 75 in the 2.0.7 version...

    Oh,it works. basically, me slug of code just adds to the html before it gets all rendered properly. Pretty simple. Just add my if statement before the line that reads
    $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';

    Oh, and thanks!

  8. ClarkH
    Member
    Posted 4 years ago #

    Thank You, tomcat23 !
    I've searched everywhere for this. It works great for me in the 2.1 version. Thank you..thank you.

  9. Andrzej Zglobica
    Member
    Posted 4 years ago #

    Maybe you can just add that behaviour by an unobstructive JavaScript call which won't require any changes in plugin core. Should be easy to setup with jQuery.

  10. Taylor Baybutt
    Member
    Posted 4 years ago #

    amazing! so glad I found this. Thanks Tomcat!

  11. nilsnh
    Member
    Posted 4 years ago #

    Tomcat23, I salute you. :) I was desperately trying to put Javascript into a stylesheet to create this effect because I wasn't sure about how to edit the plugin's Javascript. And I soon discovered that it isn't possible to do it that way, but luckily I came over this thread.

    Thanks!

  12. pixeloco
    Member
    Posted 3 years ago #

    Thank you!!
    Working in version 2.2, added the if statement to line 83.

Topic Closed

This topic has been closed to new replies.

About this Topic