0

A very quick question, I'm trying to make a comment form but I get an error on submit that the Comment field is required, even though its filled in.

No Idea why as I checked other questions etc code seems fine.

          <div class="comment-form">
                <h3> Leave a comment </h3>
                {exp:comment:form channel="blog_post"}
                    <ol>
                        <li>
                            <label>YOUR NAME<span>*</span></label>
                            <input type="text" name="name" value="{name}" />
                        </li>
                        <li>
                            <label>YOUR EMAIL<span>*</span></label>
                            <input type="email" name="email" value="{email}" />
                        </li>
                        <li>
                            <label>YOUR WEBSITE</label>
                            <input type="text" name="url" value="{url}" />
                        </li>
                        <li>
                            <label>YOUR COMMENT<span>*</span></label>
                            <textarea name="comment">{comment}</textarea>

                        </li>
                        <li class="submit"><button type="submit">POST COMMENT</button></li>
                    </ol>
                {/exp:comment:form}
            </div>

Can you spot an error? Or maybe direct me the right direction?

Thank you in advance

1
  • Is the {comment} value repopulating the form after submit, regardless of the error? And are the other values repopulating?
    – jrothafer
    May 6, 2015 at 19:25

1 Answer 1

1

Here are some things that could cause this to fail:

  1. Front-end caching such as Varnish or CloudFlare. Make sure that your cache layer is set to not cache URLs with a get parameter named ACT in them, for instance:

http://example.com/index.php?ACT=123

This is the URL format that is used to submit comments. The number will vary depending on the version of EE and other modules installed.

  1. Request rewriting that removes POST values. This is fairly common with a few variations of .htaccess / index.php removal floating around. Again you need to make sure that any URL with an ACT get parameter is not rewritten.

If neither of these seem to be the case you can do some more debugging by placing var_dump() calls in the insert_new_comment method of system/expressionengine/modules/mod.comment.php:

function insert_new_comment()
{
    $default = array('name', 'email', 'url', 'comment', 'location', 'entry_id');

    foreach ($default as $val)
    {
        if ( ! isset($_POST[$val]))
        {
            $_POST[$val] = '';
        }
    }

    // DEBUGGING
    echo '<pre>';
    echo 'POST:'.PHP_EOL;
    var_dump($_POST);
    echo 'SERVER:'.PHP_EOL;
    var_dump($_SERVER);
    exit;
    // END DEBUGGING

    ....
}

You should expect to see these variables populated in the post array, if not, something is removing the values:

  • name
  • email
  • url
  • comment
  • location
  • entry_id

A few random thoughts:

Make sure the comment is plain text, if you somehow have a WYSIWYG field added to the front-end, this may be inserting markup that is being stripped by the XSS filter.

If you are running certain web servers other than Apache they may be applying security filtering to your form submission. You would need to refer to the server's manual to see how to fix the issue in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.