Home > front end >  Form submit is not working when you press submit button once
Form submit is not working when you press submit button once

Time:08-17

I have a single page submission form. When I press the submit button it semi-loads the page once. Then when I refresh the page the form is submitted. Is there a way I can submit the form and reload the page once with out reloading or pressing the submit button twice

<?php
if(isset($_POST['submitme']) && isset($_POST['mytext'])){

 require("conn.php");
 $mytext = rtrim($_POST['mytext']); 
 mysqli_query($connection, "INSERT INTO messages (`mytext`) VALUES ('$mytext')");
}
?>
                <form id="myform" name="myform" method="POST" action="#" enctype="multipart/form-data">
                    <div >
                        <div >
                            <div >
                                <textarea  name="mytext" id="mytext" rows="3" placeholder="Your message" required>
        </textarea>
                            </div>
                        </div>
                    </div>
                    <div >
                        <div >
                            <div >
                                <input type="submit" name="submitme" id="submitme" value="Post" />

                            </div>
                        </div>
                    </div>
                </form>

CodePudding user response:

The issue seems to be with your <form> action attribute. Setting this value to # causes the form to submit to itself and will not redirect.

See what does the hash mean in action in html form tag for additional info.

So ideally, you want to leave out the action attribute entirely, which will cause the form to submit to itself and reload.

CodePudding user response:

Try remove the action attribute this should reload your page and is there any javascript?

  • Related