Ready to get started?Download WordPress


Contact Form 7
[resolved] textarea input is wrongly functioning as text input (3 posts)

  1. theresacambria
    Posted 4 years ago #

    I applied the following code to the textarea.php file and the onfocus/onblur functionality works but now the field only allows one line of text in the middle of the box, instead of multiple lines starting at the top of the box, as if it were a text input instead of textarea input.

    Here is the code I used plus a little of what comes just before it and just after for reference:

    if ( ! empty( $content ) )
    			$value = $content;
    // Default value disappears onfocus, reappears onblur if still empty
    $html = '<input type="textarea" 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 ) . '\';" </textarea>';
    	$validation_error = '';
    	if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )

    Any help would be much appreciated!


  2. Takayuki Miyoshi
    Plugin Author

    Posted 4 years ago #

    <input type="textarea" ?

    It should be <textarea

  3. theresacambria
    Posted 4 years ago #

    Thank you so much! That fixed the problem :) Great plugin, by the way.

    For anyone reading this in the future - the code I posted before, together with the correction, worked perfectly in Firefox 3.6.8 but in IE7 and IE8 the default value was acting a bit wacky. On page load it was showing all the source code that follows the contact form as the default value but if I deleted it and clicked out of the box the correct value would show up in its place. I replaced the previous custom code with this (provided by vmercader):

    $html = '<textarea name="' . $name . '"' . $atts . ' onblur="if (this.value == \'\') {this.value = \'' . esc_html( $value ) . '\';}" onfocus="if (this.value == \'' . esc_html( $value ) . '\') {this.value = \'\';}">' . esc_html( $value ) . '</textarea>';

    Now the textarea functions perfectly across the board.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic