Snippet · Mecha CMS

Code snippet collection for developers.

Store User Comment Data in the Comment Form

Author: Taufik Nurrohman · 443 Views

Tweet

Using session to store your visitor’s comment data in the comment form.

Requires comment extension.

if (!Request::is('post')) {
    $cache = [
        'author' => Request::restore('post', 'author', Session::get('comment.author')),
        'email' => Request::restore('post', 'email', Session::get('comment.email')),
        'link' => Request::restore('post', 'link', Session::get('comment.link'))
    ];
    Request::save('post', $cache);
}

Next time your visitor want to add a new comment, they will always see that the name, email and URL fields in the comment form are already filled in with their previous data.

3 Comments

  • Alexander Liebrecht

    Hi Tovic,

    In which file do I have to insert this code or is it already integrated in the system? It is already interesting, if the comment data of the users of the Mecha system are noted.

    • Taufik Nurrohman

      Put this snippet in any index.php or index__.php file.

  • Alexander Liebrecht

    Hi,
    Thanks for the hints and as you say it, it worked well. I then refresh an article and already my previously entered comment data were filled.

    This is already some convenience as I find and can be very useful.