PDA

View Full Version : Wtd: Form Validation


JamieLee2k
11-16-06, 07:48 PM
Does anyone know where I can get a form validation for my website so my members can register for tournaments on my website.

I doesn't have to be big, in fact all I need is:
Gamertag: (Required)
Email address: (Required)
Team: (Required)

Once I have a list of all the members I can use it again for the next time.

I want this in any format powweb supports, but I mainly use PHP and HTML

Chase
11-18-06, 05:50 PM
While I can't give you the best answer, I can say that I found the following for you:
http://www.chipchapin.com/WebTools/JavaScript/example1-05.html

It explains how to do it using JavaScript. That is the way you want to go. Its supported everywhere, and while you COULD do it with PHP, it'd be complex because you'd be passing the form data to a script, checking it, and having to contain it in a GET or POST to reload the form page and repopulate data for the user to fix if you find a problem in validation. Stick with JavaScript.

:-)

JamieLee2k
11-18-06, 07:06 PM
Thanks m8, I never thought I would ever get an answer. You deserve some Reputation for your help

JamieLee2k
11-18-06, 07:24 PM
I have looked at this and it looks very hard, I am no programmer so I wouldn't know where to start, I have created a html page with that info and that is as far as I got, once I got the info I need it has to saved into a page where I can view it before the tournament starts and use that info so I can edit the tournament bracket.

tpoynton
11-18-06, 08:21 PM
doing a search for javascript form validation turns up lots of results. if you want specific help, post a link to the page so people can see precisely what you are talking about.

using javascript to validate forms, while perhaps the easiest, is also not reliable because people who have javascript off will not have their info validated. php is a better way to do it, but the programming, IMHO, is a little trickier.

i think anyone reading this is already assuming you have the form set up; from your original description, however, it's not so clear.

Chase
11-18-06, 11:13 PM
I came back and saw that you said this looked hard. No worries, I didn't explain very much, and while I didn't really read the page I posted too closely, websites are sometimes not the best learning tools.

What I did was take the Javascript code on that page and placed it in the head of an html document. Some people put it right in the body, but this goes back to making sure the script is loaded before the rest of the page is, so it's been viewed as best to load javascripts in the head.

Then in the body, I took and made the form code they gave use the specific input you're looking for. I also changed the action of the form go to "foo.php" since you said you mainly use php... so I assume this is how you'll be processing the data once you have it. Obviously using the filename of your real script.

Anyway, for a simple HTML page as a working example, here is what you'd get...

This is the head:

<head>

<SCRIPT LANGUAGE="JavaScript">
function Require(obForm,szFields)
{
var fields = szFields.split(",")
var szMissing= new Array();
for (x=0;x<fields.length;x++) {
if (obForm.elements[fields[x]].value.length==0) {
szMissing[szMissing.length]=new String(fields[x]);
}
}
if (szMissing.length) {
alert("The field"+((szMissing.length>1)?"s ":" ")+szMissing.join(",")+" must be filled in first");
return false
}
return true;
}
</SCRIPT>

</head>


This is the body:


<body>

<FORM ACTION="foo.php" METHOD=POST
onSubmit="return Require(this,'Gamertag,Email,Team')">
<INPUT TYPE=TEXT NAME=Gamertag VALUE=""> Gamertag<BR>
<INPUT TYPE=TEXT NAME=Email VALUE=""> Email<BR>
<INPUT TYPE=TEXT NAME=Team VALUE=""> Team<BR>
<INPUT TYPE="RESET"><INPUT TYPE="SUBMIT">
</FORM>

</body>


That worked for me, plug it in with whatever script you're using and let me know how it goes for you.

JamieLee2k
11-19-06, 10:05 AM
Where you have put foo.php I am thinking I have to make a blank file foo.php in order for the info to go into?

Kitchensink108
11-23-06, 04:55 PM
Does anyone know where I can get a form validation for my website so my members can register for tournaments on my website.
Where you have put foo.php I am thinking I have to make a blank file foo.php in order for the info to go into?

foo.php is the form handler.You need to replace that line with the filename of the script that actually registers the members for the tournaments. If you make a blank foo.php file, when the user clicks submit, it'll just load a blank page.

JamieLee2k
12-17-06, 03:44 PM
So I understand this is working perfectly, But where does the list of players go to?