Forum

Thread tagged as: Problem, Comments, Forms

Prevent form resubmission on refresh

Hi,

I'm using a comment form within the perch_blog app. I can successfully post a comment, but every time the page refreshes the comment is then duplicated.

Here is my comment form:


<perch:form id="comment" method="post" app="perch_blog" class="comment_form" action="<perch:blog id="postURL" />"> <fieldset> <legend>Leave a comment</legend> <div> <perch:input type="text" id="commentName" required="true" label="Name" antispam="name" placeholder="Name*"/> <perch:error for="commentName" type="required">Required</perch:error> </div> <div> <perch:input type="email" id="commentEmail" required="true" label="Email" antispam="email" placeholder="Email*"/> <perch:error for="commentEmail" type="required">Required</perch:error> <perch:error for="commentEmail" type="format">Check format of address</perch:error> </div> <div> <perch:input type="url" id="commentURL" label="URL" antispam="url" placeholder="Website* (https://)" /> </div> <div> <perch:input type="textarea" id="commentHTML" required="true" label="Message" antispam="body" placeholder="Comment*" /> <perch:error for="commentHTML" type="required">Required</perch:error> </div> <div class="submit"> <perch:input type="hidden" id="postID" value="<perch:blog id="postID" />" /> <perch:input type="submit" id="submitComment" value="Submit" /> </div> </fieldset> <perch:success> <p>Thank you. Your comment has been submitted and will appear on the site once approved.</p> </perch:success> </perch:form>

Here is my post comment template:

<perch:before>
    <hr>
    <h2 class="comment_title">Comments</h2>
   <ul class="comments listing">
</perch:before>
    <li id="comment<perch:blog id="commentID" type="hidden" />">
      <img src="//www.gravatar.com/avatar/<perch:blog id="commentEmail" type="email" label="Email" order="2" hash="md5" required="true" />?s=120&d=mm" width="60" height="60" />
      <div class="comment">
        <div class="commenter">
          <perch:blog id="commentHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="1" required="true" />
          <perch:if exists="commentURL"><a href="<perch:blog id="commentURL" type="url" label="URL" order="3" />"></perch:if>
          <div>
            <span>Posted by </span><strong><perch:blog id="commentName" type="text" label="Name" order="4" required="true" /></strong>
          </div>  
          <perch:if exists="commentURL"></a></perch:if>
        </div>
        <i class="fa fa-clock-o"></i><p rel="bookmark" class="date"><perch:blog id="commentDateTime" format="%d %B %Y " type="date" time="true" label="Date" /></p>
      </div>
    </li>
<perch:after>
  </ul>
</perch:after>

Thanks in advance for any help! J

Darren Cusdin

Darren Cusdin 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does your browser not warn you that you're resubmitting the form?

No it doesn't, it must be automatically resubmitting on refresh. Even if I leave the site/page and then revisit it, the form resubmits.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's odd! We'll see if we can reproduce it.

Thank you, greatly appreciated!

Would it be useful if I sent the URL?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sure, we'll take a look.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks