/    Sign up×
Community /Pin to ProfileBookmark

Separating interface from validation

Hi,

I’m pretty new at PHP and trying to figure out what’s the best way to handle validation. In my current project I tried to separate out everything as best I could. As an example, here are the files I have for one task (adding a question to an exam):

add_question.php (displays the interface/form)
add_question_process.php (validates the form and calls functions in question.php)
question.php (a library file that does the backend work with the database)

To me it seems really sloppy sending all the form data to another page, validating it there, and then having to send the data back through the header function as GET variables, when you could just submit the form to itself, validate it there, and then call the required functions in question.php.

So my question is what is the better method to handle this? Is it best to make everything separate or is it a more common and accepted practice to include validation in the file containing the form?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehNov 15.2007 — Single point of access is always desirable over multiple ones. (Single point of access should apply to the entire website, not just one form/validation script.)
×

Success!

Help @jkelm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...