LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 01-14-2006, 05:16 PM   #1
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Rep: Reputation: 30
php validation logic


I am redesigning a program that I originally did in perl and validated with javascript. It seems the general logic for validation is to stay away from javascript because it can be turned off.

I'm looking for methods of validation with php. I am using a text file database to store the question and if they are required, easy enough. But conditional validation is something I am curious about. If a question is not required why show the question at all, the page could be refreshed to display the second question if ,for instance, a checkbox is clicked.
Is the onclick element a javascript or html element?
What are some general rules of validation that I may not know?
Am I putting way too much thought into this?

Thank you
 
Old 01-14-2006, 05:29 PM   #2
pnellesen
Member
 
Registered: Oct 2004
Location: Missouri, USA
Distribution: Slackware 12.2, Xubuntu 9.10
Posts: 371

Rep: Reputation: 31
"OnClick" is a JavaScript event; if the user has JavaScript disabled it won't work, so if that's a problem you would probably want to rewrite your JavaScript validation logic in PHP. If at all possible, put all the questions on one form so the user only has to submit once. Of course, if there's questions which can be eliminated depending on the answers to previous questions, or if you have dozens of questions, then you might want to break them up into seperate forms...

Last edited by pnellesen; 01-14-2006 at 05:31 PM.
 
Old 01-14-2006, 05:51 PM   #3
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
The problem with putting all of the questions on one form is that there is quite a few of them. It would seem overwhelming to the user. I'm thinking of storing the conditions in the database and then if the questions are needed print on a "conditional page" before going on the the next page.

**Subject Change**
Currently I store the answers in a hidden element until the end of the program. Do you think that storing arrays in hidden element is a good idea? e.g. <input type="hidden" name="Page1Answers" values="name~value&name~value&name~value">
The answers could later be parsed out into a table.
 
Old 01-14-2006, 07:11 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
Question

Storing the answers in a hidden element would probably be considered a security risk, unless you validate them again. This is because it would be possible for the user to step through the pages and then on the last page modify the html, for example add some sql injection, and then submit it.

It would be better to store the answers in a session.

graeme.
 
Old 01-14-2006, 07:16 PM   #5
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
graemef ok you have my attention. I will google of course for tutorials/articles on storing information in sessions, but do you have an article you found to be helpful with this? Are there limits to storing information in a session? I know only the basics of sessions.
 
Old 01-14-2006, 07:31 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
Sessions are fairly straight forward once the web server has been set up correctly. The steps are
  1. Start the session with session_start()
  2. access the session variables with $_SESSION['mySessionVar']
  3. close the session will be managed automatically when the script closes or with session_write_close()

So if you want to set up a session variable called name, and assign into it the value held in the local variable $name, you would do it as follows

$_SESSION['name'] = $name;

Then in a later script you can recover it with

$name = $_SESSION['name'];

Just remember that the session must be started before you try and access any session variables. Also if you are using objects then the objects stored in a session must be defined before the session is started.

I don't know of any limits (I've had sessions of several Kb before now).

I hope that helps,

graeme.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Genuine Windows Validation microsoft/linux General 1 10-11-2005 10:43 PM
email address validation rblampain Linux - Security 8 09-21-2005 02:20 AM
Confused trying to do password validation in PHP Pcghost Programming 4 02-02-2004 12:10 PM
Form validation problem (PHP+MySQL) linuxfond Programming 13 09-08-2003 12:11 PM
Validation Makaveli.2003 Programming 1 05-06-2002 08:30 AM


All times are GMT -5. The time now is 06:46 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration