View Single Post
  #1 (permalink)  
Old 04-13-2008, 02:51 AM
patricktr
 
Posts: n/a
Diggs:
Default Can you pass an array URL variable

Hi,

Doing a form which I want to validate, then re-display with error messages and
the keyed data still in place should there be errors, or go onto a second form
if all ok.

I have tried to use <form action="<?=$_SERVER['PHP_SELF']?>" but as the
various outcomes result in different screens I can't see how to do it without
having reams of duplicate code - I couldn't make it work satisfactorily anyway.

So I decided to do it in two stages - form (user screen) + a separate
validation routine which passes validation results back if there are errors by
calling the first screen but with URL variables to trigger process variations
or go onto screen 2 if all ok.

But I'm struggling with this .. two questions:

i) Ideally I would like to use a session variable to pass actual error
messages back to screen one in the event of errors but if I undertand things
correctly (which is by no means certain) $S_Session is already an associatve
array so it wouldn't be so easy to just add a variable number of messages to it
and then know what you are unpacking elsewhere ... do you know what I mean?
Perhaps if I give you my second question it may help illustrate what I'm going
on about in part 1
ii) The way I have tried to do it is to set it up as an array ($ERRORS) in the
validation module and then added a text string each time I hit a specific
error. The hope was that I could then send this back via the URL for further
process but I'm getting syntax problem so maybe this is not possible .... a
brief example ...

Input Form php:
$ERRORS = array();
$ERRORS = $_GET['errors']
if (sizeof($ERRORS) > 0) {
echo "<p class=\"val_err_hdr\"> *** Validation error(s) - please correct the
entries and try again *** </p>";
blah blah

Validation php:
$ERRORS=array();

if(!$loginFoundUser) {
$ERRORS[] = "This e-mail address entered has already been registered on our
database - if you have already registered you can"; }

header("Location: input.form.php?errors=$ERRORS");

When I run this I get a syntax error 'unexpected T_IF' on the 'sizeof''
function condition.
Any help much appreciated.



Reply With Quote
Sponsored Links