Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 16th, 2005, 11:04 AM   #1
leatheljamie
Newbie
 
Join Date: Oct 2004
Posts: 6
Rep Power: 0 leatheljamie is on a distinguished road
Exclamation help on a form

ok...

im A TOTAL beginner at this so how do i make it so when someone presses submit button and they havent filled in a form a alert message comes up and does not allow for them to continue.
leatheljamie is offline   Reply With Quote
Old Mar 16th, 2005, 11:14 AM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
you're gonna need to use JavaScript to make an actual pop-up, you can use PHP to display a message, but you can't do pop-ups with PHP. search google, there's a lot of information, and examples out there.
good luck
Dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Mar 16th, 2005, 11:17 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
You could use javascripts to check the form values.

this is what i use. i got it off of some website somewhere, i can't remember which.

 <script language="JavaScript">
 	function checkrequired(which) 
 	{
 		var pass=true;
 		if (document.images) 
 		{
 			for (i=0;i<which.length;i++) 
 			{
 				var tempobj=which.elements[i];
 				if (tempobj.name.substring(0,8)=="required") 
 				{
 		    		if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) 
 					{
 						pass=false;
 						break;
 						 }
 					  }
 			}
 		}
 		if (!pass) 
 		{
 			shortFieldName=tempobj.name.substring(8,30).toUpperCase();
 			alert("Please make sure the "+shortFieldName+" field was properly completed.");
 			return false;
 		}
 		else
 		{
 		return true;
 		}
 	}
 	</script>

Then to use it in your form do this:

 <form method="post" action="MyAction" onsubmit="return checkrequired(this);">
<input type="text" name="requiredName">
<input type="submit" value="Continue">
</form>


The important part is that you put required infront of all the fields that you want to be checked. Also you need the onsubmit part so the script gets run when the user submits the form.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Mar 16th, 2005, 2:18 PM   #4
leatheljamie
Newbie
 
Join Date: Oct 2004
Posts: 6
Rep Power: 0 leatheljamie is on a distinguished road
Exclamation

oh thanks for the code.
its working =)
leatheljamie is offline   Reply With Quote
Old Mar 16th, 2005, 2:22 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
however, know that someone can simply type:

javascript:void(checkrequired = function() {return true;});

To get past that, you need code on the server-side to truly check to make sure that the values have been entered or not. Client-side code is unreliable.
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:06 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC