Jump to content

Where to put the function that evaluate a form?


dbk

Recommended Posts

Hi

 

I have a page with a quite large form, sending the data with 'POST' action.

 

The code that handles the form data is placed in a seperate document called 'commit.php'.

 

Should I place the functions that evaluates the data in a seperate document, maybe 'evaluate.php' and if this is the way - how do I pass the data to 'commit.php'?

 

Or is the best way to put the evaluating functions in the form document?

 

And... yes I'm new to php - actually I find this passing variables between pages a bit hairy!

 

I usually use javascript to validate the form client-side with onblur() functions, but you need to have a server side validation too for security, which I usually do on the page the form is submitted to.

 

I check each value with regular expressions, or whatever I need in order to make sure it's the data I want and if they all check out clean I then clean the data for database entry, if it doesn't check out, I take them back to the form and they can try again.

You can put the evaluation code at the start of the commit.php page. That way if the data is not valid you can just redirect via a header() back to the form page passing an error message with the url as a get. Pretty simple to do and easy to understand.

 

 

HTH

Teamatomic

First off, you could create another file if you wished so but then again... There's no point!

To simply evaluate and process the data we could just do it nice and simply.

 

<?php

if (isset($_POST['only_need_one_field_name']))
{
    // Your form evaluation and processing
}
else
{
    // Your HTML form, knock yourself out 
}

 

Why did I use isset()? Simple, because if I didn't and just went on to the exactly same page without it, you'll get a nice undefined error.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.