Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Alert() and Prompt() in PHP

Tags:

php

prompt

alert

In JavaScript, we have Alert() and Prompt() which open up a popup box 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 all at once? Or can it be like JavaScript, where it waits for the user input (e.g. popup box), then executes the rest of the code after that.

like image 355
user4757174 Avatar asked Sep 20 '25 10:09

user4757174


1 Answers

PHP is a server side language, it can't do alert messages on the client side. But you can use javascript within the php to do the alert.

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

For Prompt 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);

?>
like image 60
SantanuMajumdar Avatar answered Sep 23 '25 00:09

SantanuMajumdar