LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2004, 07:54 AM   #1
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Rep: Reputation: 30
Is there a way to use a message box with PHP?


I am working on a page in PHP that deletes a record from a MySQL database but I would like a pop-up type confirmation. Similar, I think, to VBS's msgbox function. Is there anything like this available in PHP? I could always do an intermediate page to accomplish the same thing but a simple pop up would be simple. Any ideas?
 
Old 02-19-2004, 11:22 AM   #2
codedv
Member
 
Registered: Nov 2003
Location: Slough, UK
Distribution: Debian
Posts: 146

Rep: Reputation: 15
You would need to use a client side script for that. Javascripts's confirm(); function will pop-up a message and return true or false depending on whether or not the user pressed ok or not. Here's a simple example which uses check boxes and a form:
Code:
<html>
<head>
	<title>Delete Confirmation</title>
	<script language="JavaScript1.1">
		<!--
		function confirm_delete ()
		{
			// You could put code here to count the number of items selected
			
			return confirm ("Are you sure you want to delete the selected records??");
		}
		-->
	</script>
</head>
	<body>
		<form action="delete.php" method="post" onsubmit="return confirm_delete();">
			<input type="checkbox" name="record1" />&nbsp;&nbsp;Record1<br />
			<input type="checkbox" name="record2" />&nbsp;&nbsp;Record2<br />
			<input type="checkbox" name="record3" />&nbsp;&nbsp;Record3<br />
			<input type="submit" value="Delete" />
		</form>
	</body>
</html>
Simply returning false at the onsubmit event will prevent the form from being submitted.

I have put the page on my web server; if you want to give it a try it's here:
www.codedv.com/adam/delete.html
 
Old 02-20-2004, 08:43 AM   #3
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Original Poster
Rep: Reputation: 30
Thanks for the code. I will try to incorporate it today.
 
Old 02-23-2004, 12:55 PM   #4
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Original Poster
Rep: Reputation: 30
OK, I used the code and it worked exactly the way you said, but. . . . I would like to better understand what's happening. I looked up the onsubmit attribute at w3.org but it didn't give much information, at least that I could find. I understand the when you submit the form the script assigned the onsubmit attribute is called. What I don't undetstand is where is the decision being made? I assume that this particular script will return a true or false and if it's false nothing happens, the form isn't submitted. Is this the purpose of the onsubmit attribute? I would assume that it's purpose is simply to provide a way run a script the the form is submitted.

I'm sure this is pretty basic, but I just want to understand in case I could use it later.
 
Old 02-23-2004, 06:38 PM   #5
codedv
Member
 
Registered: Nov 2003
Location: Slough, UK
Distribution: Debian
Posts: 146

Rep: Reputation: 15
Its like you said. onsubmit is an event which is raised when the client attempts to submit the form. If it returns true then the form will be submitted and if it returns false it won't.

You can use the event to do some client side validation of data. e.g. a credit card number. Its worth remembering that even if you validate data client side you should always re-validate it server side. If your user has Javascript disabled - so will the onsubmit event.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell error messages not displayed as a message box!!! user222 Linux - General 10 10-25-2004 01:11 AM
Password Message Box when accessing linux box from Window Machine mikeccs Linux - Networking 1 08-04-2004 05:47 AM
How do I make a message box popup for all users? Joey.Dale Linux - General 3 04-09-2004 12:49 AM
[java] How to se font of a message box Mohsen Programming 0 03-29-2004 10:38 AM
set up a welcome message on my linux box hamish Red Hat 2 10-10-2003 08:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration