-4

I have a simple form that adds new comments on button submit. When I submit the form, the page reloads. However the result is not visible on the first refresh. When I refresh the page again, (without form re-submission) then I get to see the result. Any ideas why it behaves like that?

    <form id="formid" action="" method="POST" >
      <div>
        <textarea name="discussion" id="discussion"></textarea>
     </div>
     <div>
       <button type="submit" name="new_comment_submit" value="new_comment_submit">Submit</button>
    </div>
  </form>

The data are send as JSON and on the view I retrieve them via GET

user3192304
  • 337
  • 1
  • 3
  • 10

1 Answers1

-1

You should use header() function to direct after data saved in database on form view

  • depends on how his php looks like. That solution is just a work-around. – Chryfi Apr 15 '20 at 16:25
  • Yes, You should redirect on view page after save form data – Forge Web Design Apr 15 '20 at 16:28
  • not always. You can't use a header() function after HTML tags, which could become a problem. How is your index file going to like when you have a lot of forms. Yes, you could say that on every Post you'll use header() but what happens when you have a sort page etc.? Again... just a work-around – Chryfi Apr 15 '20 at 16:31