| | |
how can i make php alert pop ups just like in javascript.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2005
Posts: 13
Reputation:
Solved Threads: 0
I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.
I don't want a case where the user accidentally clicks on the link takes the wrong action.
i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.
i need the results from the confirm function which is either true or false so i can take appropriate action.
Is there an alternative?does php provide similar alert functions? i really need help.
I don't want a case where the user accidentally clicks on the link takes the wrong action.
i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.
i need the results from the confirm function which is either true or false so i can take appropriate action.
Is there an alternative?does php provide similar alert functions? i really need help.
•
•
Join Date: Jul 2005
Posts: 9
Reputation:
Solved Threads: 0
In short you can't. But it's very easy to get the same confirmation that you would with a alert box.
1. Pass ID/Email of record along with the delete command, easiest to use a URL
e.g.[PHP] <a href="confirm_delete.php?id=<idofemailrecord>">Delete Me</a>[/PHP]
2. On your confirm_delete.php page create two URLs yes or no
e.g.
[PHP]Are you sure you want to delete:
<br>
<a href="delete.php?confirm=yes&id=".$_GET[id].">Yes</a>
<a href="delete.php?confirm=no&id=".$_GET[id].">No</a>[/PHP]
Then on the delete.php page you have some like the following:
[PHP]
if ( $_GET[confirm] == "yes" )
{
mysql_query( "DELETE FROM table WHERE id= '".$_GET[id]."'" );
} else if ( $_GET[confirm] == "no" )
{
header( "location: http://www.yourhomepage.com");
}[/PHP]
Of course this is extremely basic. You would really want to check the variables $_GET[confirm] and $_GET[id] to make sure a hacker wasn't trying to do a sql injection attack on your form. But that's for another discussion. Hope that helps.
1. Pass ID/Email of record along with the delete command, easiest to use a URL
e.g.[PHP] <a href="confirm_delete.php?id=<idofemailrecord>">Delete Me</a>[/PHP]
2. On your confirm_delete.php page create two URLs yes or no
e.g.
[PHP]Are you sure you want to delete:
<br>
<a href="delete.php?confirm=yes&id=".$_GET[id].">Yes</a>
<a href="delete.php?confirm=no&id=".$_GET[id].">No</a>[/PHP]
Then on the delete.php page you have some like the following:
[PHP]
if ( $_GET[confirm] == "yes" )
{
mysql_query( "DELETE FROM table WHERE id= '".$_GET[id]."'" );
} else if ( $_GET[confirm] == "no" )
{
header( "location: http://www.yourhomepage.com");
}[/PHP]
Of course this is extremely basic. You would really want to check the variables $_GET[confirm] and $_GET[id] to make sure a hacker wasn't trying to do a sql injection attack on your form. But that's for another discussion. Hope that helps.
•
•
Join Date: Oct 2006
Posts: 1
Reputation:
Solved Threads: 0
Maybe you can use:
<?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?>
//Khanobly
<?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?>
//Khanobly
•
•
•
•
I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.
I don't want a case where the user accidentally clicks on the link takes the wrong action.
i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.
i need the results from the confirm function which is either true or false so i can take appropriate action.
Is there an alternative?does php provide similar alert functions? i really need help.
•
•
•
•
I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.
I don't want a case where the user accidentally clicks on the link takes the wrong action.
i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.
i need the results from the confirm function which is either true or false so i can take appropriate action.
Is there an alternative?does php provide similar alert functions? i really need help.
The confirm box is a function on the browser, so you cannot create a browser confirm box with php unless you use PHP to write out some javascript that will be executed on the browser to display your cofnirm box. (see khanobly's reply)
The only way you can communicate with the php on the server side via javascript is to send the server a new HTTP request (a new page). (exception being xmlHTTPRequest).
In your case, the confirmation box should work just like a normal click on a link (you dont need the javascript to communicate with the php).
eg:
<a href="task.php?option=delete">Delete</a>
Lets say the above will invoke the php script task.php and let it know you want to delete something from the database.
We can use javascript to make sure the user doesn't delete by accident.
<a href="task.php?option=delete" onclick="return (confirm('do you really want to delete the stuff?'));>Delete</a>
When the user clicks the link, the onclick event handler in javascript is triggered. The onclick handler overides the loading of the url in the href attribute but if the onclick function returns true (or null) the browser will then load the url in the href attribute. If the onclick function returns false the url will not load.
confirm, returns true or false depending on what the user chooses (yes|no). So we just return the return from the confirm function to the onclick event trigger and thus the link will be followed or not depending on the users choice.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- System alert pop-ups (Viruses, Spyware and other Nasties)
- spyware, pop-ups and more; amaena?? (Viruses, Spyware and other Nasties)
- Unable to remove Virus Alert, Pop Ups & IE Start Up page .. help ... (Viruses, Spyware and other Nasties)
- pop ups wont stop (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: A List Script?
- Next Thread: convert database into XML
| Thread Tools | Search this Thread |
.htaccess ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl customizableitems database date delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube






