Forum Moderators: coopster

Message Too Old, No Replies

Getting error messages back from form processing page

         

clkdesign

5:03 pm on Jul 16, 2009 (gmt 0)

10+ Year Member



I'm having troubles getting back error messages from a php file that my form is being sent to for processing. So this is a basic example of what I have:

sign_up.php

<form action="signup_processor.php" method="post">
<!--form input here -->
<input type="submit" />

signup_processor.php

<?php

if(array_key_exists("submit", $_POST) {
//page validation, make sure the form is coming from the accepted pages only

$username = trim($_POST['username']);

//other input cleaning code would be here

//now we connect to the database and look for a row with the same user name and put the results into an array called $numRows

if($nubRows) {
$error[] = "Username already in use, please pick a diffrent name"
header( "Location: sign_up.php&errors=". $error .);
exit;
}
else {
//script continues processing

Okay so my question is, how do I get the $error array BACK from 'signup_processor.php' without using the above method? the above method *works* but it is very messy, especially when you have a form with 10+ fields in it. I'm working to upgrade a CMS that does this EVERYWHERE. It also poses a problem because all the error messages are printed out row by row above the form were ideally I would like to put a specific error message above the input field that it pertains to.

Any suggestions would be great, I can't really find any method besides the one I mentioned or using JavaScript which is not feasible for a CMS that has 20+ forms that are being validated with the above example.

clkdesign

6:23 pm on Jul 16, 2009 (gmt 0)

10+ Year Member



I had a thought... if I made a function to handle the error messages and put them into a $_SESSION or a $_COOKIE would there be anything wrong with passing information this way?