• I am trying to achieve what’s been asked in this post basically how to clear input fields when you click…the answers to linked post don’t seem to work with Contact Form version 2.4.6

    I have managed to get it working on the text input fields…but not the text area fields…by adding this to modules/text.php

    ‘backticks’ if ( $value != ” ) {
    $atts .= ‘ onfocus=”if (this.value == \” . esc_attr( $value ) . ‘\’) {this.value = \’\’;}” onblur=”if (this.value == \’\’) {this.value = \” . esc_attr( $value ) . ‘\’;}”‘;
    }
    $html = ‘<input type=”text” name=”‘ . $name . ‘” value=”‘ . esc_attr( $value ) . ‘”‘ . $atts . ‘ />’;’backticks’

    site I am working on is here

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter Kanger

    (@kanger)

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

    (@anonymized-8209903)

    I want this on my contact form as well, but I would be happy just to have it ony the name and Email field. Which part of the code do I replace with `’backticks’ if ( $value != ” ) {
    $atts .= ‘ onfocus=”if (this.value == \” . esc_attr( $value ) . ‘\’) {this.value = \’\’;}” onblur=”if (this.value == \’\’) {this.value = \” . esc_attr( $value ) . ‘\’;}”‘;
    }
    $html = ‘<input type=”text” name=”‘ . $name . ‘” value=”‘ . esc_attr( $value ) . ‘”‘ . $atts . ‘ />’;’backticks’`

    ?

    Thanks in advance ??

    Thread Starter Kanger

    (@kanger)

    I think it was line 88…i can’t remember now…and can’t find where I got it from…basically part that says ‘html = input type…

    this link may help

    I’ll look through my history and try and find originally post where I got my half solution from

    Thread Starter Kanger

    (@kanger)

    D’oh!!

    Ok on all the solutions I couldn’t find the line for text area…realised I had to edit textarea.php file as well as text.php would help if I could read ??

    so yes link here works great, just realise that the top half is refering to changes in text.php file and the second half the text

      area

    .php file

    Anonymous User 8209903

    (@anonymized-8209903)

    Hmm, I’ve tried editing both text.php as well as textarea.php, but nothing seems to be working. Is there another tweak that I have to do in order for the textfields to display something in the first place?

    For example, I want the first textfield to display a greyed out “Name” that disappears once the user clicks on the textfield. How do I accomplish this? ??

    Thread Starter Kanger

    (@kanger)

    are you using contact form 7?

    should have something like this…

    [text* your-name “Your Name….”]

    and whatever between “” will show up infield.

    If that’s what you mean…not sure

    Anonymous User 8209903

    (@anonymized-8209903)

    THAT was the issue! I had just written [text* your-name] and nothing else :P. Thank you very much! While on the subject, do you know if there’s any way to collapse the whole contact form after an e-mail has been sent successfully? So that the sender will just view the “message has been sent”-message upon clicking the “Send”-button?

    Thread Starter Kanger

    (@kanger)

    Ooh sounds like a cool thing to do..I don’t know how to do it I’m afraid, but I’m sure it’s possible…maybe start another thread.

    Thread Starter Kanger

    (@kanger)

    don’t know if playing around with this would work…

    let me know how you get on

    Anonymous User 8209903

    (@anonymized-8209903)

    I will, once I get the hang of it :).

    An issue with the first problem though. Everything works perfectly except for one thing. The new code removes the requirement for name and subject, so if a user doesn’t type in anything at all, all he gets is an error message stating that the e-mail address isn’t valid. If he puts in a mail address and clicks send the mail gets sent (even though the user hasn’t added his name or the subject).

    Another issue is that once the user has pressed “Send”, the fields become completely empty and all white instead of having a greyed out “Name/E-mail/Subject” in them.

    Any thought on how to solve this?

    Anonymous User 8209903

    (@anonymized-8209903)

    NVM, solved the first problem by adding watermark in front of “name”.

    The second problem is still there though, once a user sends his or her mail, all the watermarks disappears.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Contact Form 7 – clearing fields on input’ is closed to new replies.