WordPress.org

Support

Support » Themes and Templates » [Resolved] Call function in comment field to pull cookies or default

[Resolved] Call function in comment field to pull cookies or default

  • This is my goal: I want my comments form fields to be filled in automatically with cookies if they exsist and if they do not I want the fields to default to “Name”, “Email”, “Url” when not focused (onblur).

    This is what I’ve done: I’ve included the following atributes to the <input> fields:

    onfocus="if(this.value==this.defaultValue)value=''" onblur="if(this.value=='')value=this.defaultValue;"

    For the value of the <input>, I’ve put:

    value="<?php commentauthor($comment_author,Name) ?>"

    And in the header, I've included the following script:


    <script>
    function commentauthor(cookie,default)
    {
    if (cookie)
    return cookie;
    else
    return default;
    }
    </script>

    Problems: When I load the page, it says that my function is undefined (fatal error). Did I do something wrong in defining the function?

    Also, is there a better way to do this, maybe something built into Word Press that I don’t know about? This should work fine, I think if I can get it to work, but any other suggestions?

Viewing 1 replies (of 1 total)
  • I’ve been working on this all day long and I knew I should have worked on it 5 more mintues before posting for help…. I figured it out.

    Instead of calling a function, I just wrote this for my value attribute:

    value="<?php if ( $comment_author ) { echo $comment_author; } else {echo "Name";} ?>"

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Call function in comment field to pull cookies or default’ is closed to new replies.
Skip to toolbar