Equivalent to Alert () and Prompt () in PHP

In JavaScript, we have Alert () and Prompt () that open a popup for the user.

Is there an equivalent for PHP? $Get_['asdf']

is one way to get user input ... any others?

Also, one more question. Is it a requirement that PHP always be executed right away? Or it could be like JavaScript where it waits for user input (like a popup) and then executes the rest of the code after that.

+3


source to share


3 answers


PHP is a server side language, it cannot generate client side warning messages. But you can use javascript inside php for warning.

<script type="text/javascript">
window.alert("Hi There, I am the Alert Box!")
</script>

      



For a hint, you can do something like this -

<?php

    //prompt function
    function prompt($prompt_msg){
        echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");

        $answer = "<script type='text/javascript'> document.write(answer); </script>";
        return($answer);
    }

    //program
    $prompt_msg = "Please type your name.";
    $name = prompt($prompt_msg);

    $output_msg = "Hello there ".$name."!";
    echo($output_msg);

?>

      

+6


source


No, there is no equivalent. All php is only executed on the server side. If you are not using it on the command line, which I doubt.



It also can't wait for user input like javascript as you wanted. I'm sorry. You will need to use ajax for this.

+2


source


This:

$should_proceed = readline('Are you wanna proceed?(y/n): ');
if (strtolower(trim($should_proceed)) == 'n') exit;
proceed();

      

0


source







All Articles