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!

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.