/    Sign up×
Community /Pin to ProfileBookmark

php serverside form validation

i was wondering how you set up your logic to do form handling. i’d also like to mention that i’m using OOP (if that makes a difference)

my problem arises when i’m redirecting and am unable to send over the POST variables that were submitted.

for example, if a user submits a form and misses some required fields, i’d like for the form to redirect back to the original page and display the $_POST variables in the proper field.

however, if the user fills out the form correctly, it’d just direct them to the next page.

what i was thinking was to do the validation on the same page as the form, then if it’s successful insert it into the DB on the same page then refer the user to the next step.

how do you all set this up?

also, is it possible (and if so, how and which tutorials are useful) to following the MVC guide without using any existing frameworks?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 15.2008 — One solution is to have the same main script handle both the form display [i]and[/i] processing. The actual form output and form handling can still be in separate files (classes?), but have them included into the main page as/when needed. Then the $_POST data is available to each. No matter what you are doing.
×

Success!

Help @ixxalnxxi 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...