How to avoid page reload in php form submission

raju

I am currently using php in my html page and there is an action in the same page which gets executed upon form submission. Currently whole form gets reloaded while I want the php action to be run in the background with out reloading. How do I do it. I would also want to clear the text box after submit button is clicked. Following is the code I am currently using

<html>
<head>
</head>

<body>
    <form action="index.php" method="post"  role="form">
        <input type="email" placeholder="Enter email"  name="email_address">
        <button class="btn btn-primary custom-button red-btn">Sign Up</button>
    </form>

<?php



if(isset($_POST['email_address'])  !(trim($_POST['email_address']) == ''))

// do some action
}

?>
</body>

</html>

Note: Following code worked for me

<script type="text/javascript">
    $('#contactForm').submit(function () {
       $.post("mailer.php",$("#contactForm").serialize(), function(data){
       });
        return false;
    });
</script>
Praveen Kumar Purushothaman

You need to use AJAX for this, for without reloading. Or, if you want to do it without disturbing the page, you need to set target.

Using AJAX

$("form").submit(function(){
  $.post($(this).attr("action"), $(this).serialize());
  return false;
});

Using target

<form action="index.php" method="post" role="form" target="_blank">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Preventing page reload upon form submission to database

From Dev

How to avoid duplicate form submission?

From Dev

Form submission opens php page

From Dev

How to show the success message of PHP in html page on Form submission

From Dev

How to redirect page on form submission

From Dev

Trigger form submission with $.submit() and prevent page reload at the same time

From Dev

No response after form submission and page just auto reload

From Dev

Don't reload page after form submission using ajax and jquery

From Dev

php return to page after form submission

From Dev

php return to page after form submission

From Dev

how to submit form with ajax and php to avoid page refresh

From Dev

Prevent page reload after submission

From Dev

How to avoid reload after php code execution?

From Dev

How to show the image uploaded using HTML file control on a new page after form submission in PHP?

From Dev

Bootstrap Toggle avoid form submission

From Dev

Using jQuery AJAX to call a php page on form submission

From Dev

Can't get rid of blank php page after submission form

From Dev

Form Submission to Self (PHP)

From Dev

PHP contact form submission

From Dev

PHP, email submission form

From Dev

How to avoid page reload after inserting data into the gridview

From Dev

Form reset on page reload?

From Dev

How to redirect to new html page after form submission in Apps script

From Dev

Does a form refresh the page on submission?

From Dev

php update mysql table via form, reload information on page immediately

From Dev

How to show a success message after PHP form submission?

From Dev

how to clear form using php PDO after successful submission

From Dev

Reload form in dialog box without page reload

From Dev

How to prevent form input to reload a page when receiving `Enter` key

Related Related

  1. 1

    Preventing page reload upon form submission to database

  2. 2

    How to avoid duplicate form submission?

  3. 3

    Form submission opens php page

  4. 4

    How to show the success message of PHP in html page on Form submission

  5. 5

    How to redirect page on form submission

  6. 6

    Trigger form submission with $.submit() and prevent page reload at the same time

  7. 7

    No response after form submission and page just auto reload

  8. 8

    Don't reload page after form submission using ajax and jquery

  9. 9

    php return to page after form submission

  10. 10

    php return to page after form submission

  11. 11

    how to submit form with ajax and php to avoid page refresh

  12. 12

    Prevent page reload after submission

  13. 13

    How to avoid reload after php code execution?

  14. 14

    How to show the image uploaded using HTML file control on a new page after form submission in PHP?

  15. 15

    Bootstrap Toggle avoid form submission

  16. 16

    Using jQuery AJAX to call a php page on form submission

  17. 17

    Can't get rid of blank php page after submission form

  18. 18

    Form Submission to Self (PHP)

  19. 19

    PHP contact form submission

  20. 20

    PHP, email submission form

  21. 21

    How to avoid page reload after inserting data into the gridview

  22. 22

    Form reset on page reload?

  23. 23

    How to redirect to new html page after form submission in Apps script

  24. 24

    Does a form refresh the page on submission?

  25. 25

    php update mysql table via form, reload information on page immediately

  26. 26

    How to show a success message after PHP form submission?

  27. 27

    how to clear form using php PDO after successful submission

  28. 28

    Reload form in dialog box without page reload

  29. 29

    How to prevent form input to reload a page when receiving `Enter` key

HotTag

Archive