form help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

form help

Post by method_man »

how can i make it so that on my register page all forms have to have something typed in and all drop down boxes have to select something besides the default?

also how can i make it so it displays a javascript box that says Email Addresses don't match if Email Address and Confirm Email Address dont match? Same thing with password and confirm password


thanks,

matt
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Sounds like you need a javascript solution....

In the from tag ad onsubmit="checkForm();"

Then build the function.

Code: Select all

function checkForm(){
  if (document.formname.fieldname.value == ""){ ///Check the value of the field
     window.alert('some message');
  }
}
It would look something like that...

There are lots of toots on the web for stuff like this.
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post by trukfixer »

I dont rely on javascript for that - I post the data to the handler script, (typically posts back to itself) and then check post data for parameters (empty values, dirty data, numbers where you only want letters, etc) and assign errors to an array (or a string) and re-display the form prepopulated with the previously submitted data (and using CSS to highlight in an "alert" color, the fields that gave errors, along with the error messages) whe they get all teh data required submitted (and cleaned somewhat) I assign all data to SESSION data and redirect to the php script that processes the data and does whatever with it, then redirect to whatever "results" page I want to display to them - it's a lot more work that using JavaScript, but if it is mission critical data, it's a heck of a lot more secure (A user can just turn off JavaScript and still submit dirty data or empty data to your form, or post it from another form that doesnt have JavaScript on it, so JavaScript is at best just a "page pretty-upper" - there *are* some uses for Javascript that help enhance security quite well, but none of it does any form input validation :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Some one correct me if I'm wrong but if you config your pop-up blocker to block all pop-ups won't some them even block alerts? If that person has turned off their notification too they may never know something was wrong....
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

thanks :D
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I've used AJAX validation for this. Works great. OnBlur of each form field send the form values & validate that they are the same and valid. On return set a div tag to display an error or success.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Or even an onchange, as the users type their email they see a red X, as soon as it detects the emails matching it changes to a green check
supernerd
Forum Newbie
Posts: 2
Joined: Fri Dec 23, 2005 6:39 pm

Post by supernerd »

Check out Zoopframework

It has integrated form validation using it's guiControls component. It integrates both javascript and php validation and supports required and many different format typing like phone, creditcard, numeric, etc...
GuiControls work using normal posts, or through AJAX.

You can find zoop at http://zoopframework.com. It has pretty extensive documentation and also has a forum where you can get help.

They even have a movie there to show you the form validation in action.
Post Reply