Mecha CMS

Mecha CMS blog and documentation.

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 = alter($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.