skip to Main Content

I have not used php before and I do not know how to add a pop-up window there after successful sending, since what pops up after sending is: echo (‘The email has been successfully sent!’);, and I want to make this pop-up written in js, is it possible to somehow turn to pop-up in php.

I haven’t tried anything since I don’t know php.

2

Answers


  1. PHP works on the server and is not interpreted in the browser. What you want to do is to have PHP send back javascript code which will be interpreted by the browser and does whatever you want (open a pop-up).

    So if you call a PHP script in simple POST or GET method, then your browser will actually be served a new page from PHP. And you can write whatever you want in the PHP result, so this should be a mixture of html and javascript:

    echo ('<html>
      <head>
        <script type="text/javascript">
          here is your code for the popup
        </script>
      </head>
      <body>
        whatever you want to write in the body of the page returned by php
      </body>
      </html>');
    

    In case you work with AJAX calls you have to make sure that your AJAX implementation (you probably use javascript and some framework for it) actually interprets javascript code when receiving the result.

    Login or Signup to reply.
  2. I’m combining javascript and PHP bootstrap like this:

    bootstrap html:

    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-body" id="msgid"></div>
    </div>
    

    Javascript
    for example sending to signup form

    $.ajax({
            url:"http://localhost/signup.php",
            type:"POST",
            data:$("#frmsignup").serialize(),
            success:function(response) {
                var result=JSON.parse(response);
                if (result.success){
                    $("#msgid").html(result.message);
                    $(".toast").toast({
                        delay:1000
                    }).toast('show');
                }
            },
            error:function(){
                $("#msgid").html("Error");
                $(".toast").toast({
                    delay:1000
                }).toast('show');
            }
        });
    

    PHP
    after processing, add this for success/failed message

    $message=array(
              "success"   => true/false,
              "message"   => ""
              );
    echo json_encode($message);
    

    change success to true or false to perform success or failed.

    This is work for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search