WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Call function in comment field to pull cookies or default (2 posts)

  1. Sphagnum
    Member
    Posted 8 years ago #

    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?

  2. Sphagnum
    Member
    Posted 8 years ago #

    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";} ?>"

Topic Closed

This topic has been closed to new replies.

About this Topic