Mecha CMS

Code snippet collection for developers.

Store User Comment Data in the Comment Form

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

Requires comment extension.

if (!HTTP::is('post')) {
    $previous = (array) Session::get('comment');
    unset($previous['content']); // Remove `content` cache
    $cache = extend($previous, (array) Session::get('form'));
    Session::set('form', $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.