Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MessageBox / Dialog 1

Status
Not open for further replies.

miguelleeuwe

Programmer
Oct 17, 2007
242
NL
Hello,

I want to inform my users by means of a messagebox from php code.
I've seen code but it all works with javascript and are based on the execution of 'something' like a submit button.

The php-ext library also seems very interesting but I haven't been able to something as simple as, though I'm still trying (can't figure out how to create a message and call it):
-------------
<?php
messagebox('Finally', 'It worked!')<
?>

Any help greatly apreciated,
miguel

regards,
Miguel L.
 
Short answer: You can't.

Long Answer:
PHP runs on the server, so there's no way for it interact with the browser and create a message box.

You can use a combination of Javascript and PHP to get the effect you want.

How you implement this will depend on what action will trigger the message box.

For instance if I wanted to produce a message box that pops up once a user logs in and as the main user page is opening I could generate an onLoad event for the body of the page with the value and have JS popup the box as the page loads.

Code:
<html>
<?PHP

$user = "Mike";

$messagebox=<<<EOS
onLoad="alert('Welcome $user to the site');"
EOS;

?>

<body <?PHP echo $messagebox; ?> >
...
</body>
</html>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thank You,

that explains a lot of my misery ..

"How you implement this will depend on what action will trigger the message box."

Is there any way I can define 'my own' action and trigger that one from php?

Greetings,
Miguel


regards,
Miguel L.
 
No, you'll rely, mostly on Javascript actions to do this.
As that is at the end what is producing the dialog.

When exactly is it you wan to trigger the message box?






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I'm having a new user introduce his data in a form.
After validating the data I do an insert into a table. When Mysql returns an certain errocode which indicates that the user already exists, I want to inform him that he has to choose another login name.

Another example that is very much alike: When a user already exists and wants to do a normal login: inform him when the user he typed, does not exist.

I'll probably have to revise the whole login: submitting to a javascript function instead of php and run php code from the javascript function? I think that might be more easy?

thanks again,
miguel

regards,
Miguel L.
 
After trying lots of advanced stuff (for a newby like me).

I finally found an simple and acceptable solution:
- have a Javascript function.
- call it by echoing the calling javascript code..
;) You people don't know how happy I am....
-------------------------------------------


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "<html>
<head>
<script type="text/javascript">
function show_alert( msgtext)
{
alert('hello this is my message');

}
</script><title></title>
</head>
<body>

<?php
echo '<script type="text/javascript">';
echo "show_alert();";
echo "</script>";
?>
</body>
</html>


regards,
Miguel L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top