Re: Equivalent of Javascript "confirm" dialog box
| From: | Folke Ashberg | Date: | Sat, 25 Nov 2000 01:56:44 +0000 |
| Subject: | Re: Equivalent of Javascript "confirm" dialog box | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27073@lists.php.net to get a copy of this message | ||
Hi!
The not such easy as in JS, because PHP is ServerSide an JS ClientSide!
<script>
if (confirm("Do you like PHP?")) alert("Cool, like me!"); else
alert("what???");
//the source continues...
</script>
is easy, because Netscape (or IE :( ) can wait until the user has decided
what to do (or if he like PHP).
Not with PHP. I think ya know that PHP produces the HTML output and stops
then. What you have to do is to generate with php the JS source with the
confirm dialog and after the confirm you can submit the page to the php
again.
example:
---
print "<form name=\"theform\" action=\"$PHP_SELF\">\n";
//now pass variables you need to pass to the following php-script
print "<input type=hidden name=\"username\"
value=\"$username\">\n";
//now create an "empty" form-input type which will be filled out from
javasrcipt
print "<input type=hidden name=users_choice value=\"\">\n";
print "</form>\"n;
//and now output the dialog-js-source
//and autosubmit the form after the users choice
print "
<script language=\"JavaScript\">
if (confirm("Do you like PHP?"))
document.theform.users_choice.value='cool';
else document.theform.users_choice.value='forgot_him';
document.theform.submit();
</script>
";
now the same script is called (if you use $PHP_SELF in forms action) and
will receive the passed variables and also $users_choice
OK? :)
regards
Folke
--
Folke Ashberg
Stage Internet Services GmbH
Technical Development
folke@fanstage.de
folke@fanstage.de | Tel: +49 89 454591-77 | Fax: +49 89 454591-71
Kreillerstr. 21 | 81673 Munich | Germany | www.fanstage.de
On Sat, 25 Nov 2000, Peter Wade wrote:
>
> Hi, Can anyone point me in the right direction to emulate in PHP4 a Confirm
> dialog box in a separate window a la Javascript?
>
> Thanks,
>
> Peter
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Hear Peter Wade & Norman Campbell live January 2001:
> Halls Gap, Victoria, Australia.
> Biblical insights for you at the Positive Words site:
> < http://www.posword.org/ >
> < http://i.am/in.Christ/ >
> Free newsletter... email to <subscribe@posword.org>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>