Calling PHP and dialog box on one click together

Asked
Active3 hr before
Viewed126 times

6 Answers

clickdialogcalling
90%

I have a form where I want to show user their input data in dialog box and to save in SQL using PHP in one click only. Problem is I can call only one (either dialog box or PHP) at one time. As dialog box requires anchor tag , Stack Overflow Public questions & answers , Meta Stack Overflow , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

Write the submit function inside the ok function of dialog.

<a href="#" value="Save" onclick="submit()">Save</a>
<script>
document.forms["myform"].reset();
$(function(){
    $("#dialog").dialog({
        autoOpen:false,
        modal:true,
        width:400,
        height:300,
        buttons:{
            "OK": function(){
                    $("#your_form_id").submit();// also you can call ajax here if you don't want to reload the page
                    $(this).dialog("close");
                    alert("Saved");

                },
            "Cancel":function(){
                    $(this).dialog("close");
                }
        }
    });

});
function submit(){
    $("#location").html($("#pac-input").val());
    $("#type").html($("input:radio[name='sex']:checked").val());
    $("#open").html($("#open").val());
    $("#close").html($("#close").val());
    $("#review").html($("#review").val());
    $("#rating").html($("input:radio[name='rating']:checked").val());
    $("#dialog").dialog("open");
    }
</script>
88%

Let’s take a look with the GET or POST methods, as most developers use POST method due to privacy issues, the following example is based on POST method only:,Calling a PHP function using the HTML button: Create an HTML form document which contains the HTML button. When the button is clicked the method POST is called. The POST method describes how to send data to the server. After clicking the button, the array_key_exists() function called.,How to call PHP function on the click of a Button ?,How to delete an array element based on key in PHP?

72%

Alert boxes are used for displaying a warning message to the user. As you know that PHP does not have the feature to popup an alert message box, but you can use the javascript code within the PHP code to display an alert message box. In this way, you can display an alert message box of Javascript in PHP.,To pop an alert message via PHP, we need to render JavaScript code in PHP and send it to the browser. JavaScript is a client-side language.,PHP is a server-side language and does not support pop-up alert messages. The browser of the client renders an alert.,An alert box is nothing but a pop-up window box on your screen with some message or information which requires user attention. 

Example: Using the JavaScript alert box

<html>

<head>
   <meta charset="utf-8">
   <title>JavaScript Alert Box by PHP</title>
   <?php  
echo '<script type="text/javascript">';
echo ' alert("JavaScript Alert Box by PHP")';  //not showing an alert box.
echo '</script>';
?>
</head>

<body>
</body>

</html>
load more v
65%

In this lesson, you will use JavaScript to display an alert after the web page has loaded. ,Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events. When the page loads, or when a user clicks on, hovers over, or tabs to a specific link, these are all events. We can instruct JavaScript to watch for these events, and if or when they occur, execute the specified function.,Try modifying your showAlert() script with your own custom alert message. Then test it to be sure it works.,For example, let's say we want to execute the showAlert() function after the body of the web page is fully loaded. One way to do that is to add the onload attribute to the <body> element of our web page, like this:

Add the following JavaScript code to the <head> section of your web page:

  <script>
  function showAlert() {
    alert ("Hello world!");
  }
  </script>
load more v
75%

Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button "OK" to select and proceed.,Javascript - Operators,A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel.,Javascript - HTML DOM

<html>
   <head>   
      <script type = "text/javascript">
         <!--
            function Warn() {
               alert ("This is a warning message!");
               document.write ("This is a warning message!");
            }
         //-->
      </script>     
   </head>
   
   <body>
      <p>Click the following button to see the result: </p>      
      <form>
         <input type = "button" value = "Click Me" onclick = "Warn();" />
      </form>     
   </body>
</html>
load more v
40%

The overall AJAX call works something like this:,The usual approach would be to build different web pages for each section. So for example, users would click the social information link to reload the browser and display a page with the social information. This makes it slower to navigate between sections, though, since the user has to wait for the browser to reload and the page to render again each time.,In the next section, we’ll see a real-world example to understand how this all works with PHP.,So as you can see, the web page is updated with real-time data from the server without the browser reloading.

Let’s have a look at the following vanilla JavaScript code, which performs the AJAX call and fetches a response from the server asynchronously.

<script>
var objXMLHttpRequest = new XMLHttpRequest();
objXMLHttpRequest.onreadystatechange = function() {
  if(objXMLHttpRequest.readyState === 4) {
    if(objXMLHttpRequest.status === 200) {
          alert(objXMLHttpRequest.responseText);
    } else {
          alert('Error Code: ' +  objXMLHttpRequest.status);
          alert('Error Message: ' + objXMLHttpRequest.statusText);
    }
  }
}
objXMLHttpRequest.open('GET', 'request_ajax_data.php');
objXMLHttpRequest.send();
</script>
load more v

Other "click-dialog" queries related to "Calling PHP and dialog box on one click together"