How to Validate Text and Submit Button?

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
umapathy
Forum Newbie
Posts: 14
Joined: Fri Jul 28, 2006 2:21 am
Location: chennai - india

How to Validate Text and Submit Button?

Post by umapathy »

Hi all

i have one problem in my page.
i have four textboxs.

1. Should Accept only Character
2.Should Accept only Number
3.Should check date format.
4. should check upload file.

in the above four if i leave blank or type miss match a error should indimate to the user when he clicking the Submit Button.
How is possible.?
Can you guide me?


Thanks and Regards
Umapathy
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

First of all, take a look at isset() and empty().

1. ctype_alpha()
2. ctype_digit()
3. Use select boxes to force your own format and check the range of the day, month and year - each one separately.
4. exif_imagetype(), getimagesize() and move_uploaded_file()

- Get yourself a good book.
- Read related topics on the forums here.
- Read online tutorials.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

3. Use select boxes to force your own format and check the range of the day, month and year - each one separately.
Remember just because the user can only choose from select options doesn't mean a hacker can't specify his own. Validate the date is correct on the server as if it was entered as text.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

ole wrote:Remember just because the user can only choose from select options doesn't mean a hacker can't specify his own. Validate the date is correct on the server as if it was entered as text.
Read my post again pal... I think I was clear enough when I told him to check the ranges :P
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Sorry oren didn't see that.
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

Post by angelena »

Below is some codes which hopefully helps u :

Let say u have a submit button names var and value as add

Code: Select all

<input type=submit value="add" name="var">

Then your validation once a submit button clicked is :

Code: Select all

//if add button is clicked
    if($var == 'add')
	{
	   
                  ...do your checking here		
	}
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

Here it is a good PHP tutorial http://codewalkers.com/tutorials/47/1.html.
Another tutorial here: http://www.php-mysql-tutorial.com/form- ... th-php.php.
Use them as an example do not copy the code.
Good luck!
Post Reply