Adobe Dreamweaver Forums



Last 10 THreads :         cfif (Last Post : Ian Skinner - Replies : 3 - Views : 4 )           »          Help posting folder to server (Last Post : Dawgswrestler - Replies : 2 - Views : 3 )           »          Problems producing W3C-valid template-built pages (Last Post : hen3ry - Replies : 0 - Views : 1 )           »          PHP Server lets Cookies work but not Sessions! (Last Post : Rickideeuk - Replies : 8 - Views : 9 )           »          Question about filtering commas (Last Post : Ian Skinner - Replies : 1 - Views : 2 )           »          Error: ModuleManager.as:671 (Last Post : Amy Blankenship - Replies : 10 - Views : 11 )           »          Flickering tooltip in bottom right corner (Last Post : Amy Blankenship - Replies : 5 - Views : 6 )           »          Visited Link appears as default (Last Post : Mark A. Boyd - Replies : 6 - Views : 7 )           »          Can't uninstall dreamweamweaver cs4 beta (Last Post : Mark A. Boyd - Replies : 7 - Views : 29 )           »          Dreamweaver 8 problem (Last Post : Mark A. Boyd - Replies : 6 - Views : 9 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Dreamweaver: Main > Dreamweaver Application Development
 
Tags: , , ,



Reply
  #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
  #2 (permalink)  
Old 04-13-2008, 02:51 AM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: Can you pass an array URL variable

.oO(patricktr)

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


OK, quite common.

> I have tried to use <form action="<?=$_SERVER['PHP_SELF']?>"


Avoid short open tags, they are unreliable. Use "<?php print " instead
of just "<?=" to be safe and independent from the server configuration.

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


What's a "screen" in this case? Just another part of the form or a
completely different page?

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


Don't use URL parameters in such a form processing scenario. Use a
session instead, that's what they are for. The length of URLs is limited
and there are things you simply don't want to pass between pages, but
keep on the server instead.

> 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?


The $_SESSION array itself is strictly associative, the used indexes
must be strings or the serialization of the session data will fail.
But if course you can always do things like this:

$_SESSION['errors'] = array();
$_SESSION['errors'][] = 'something went wrong';

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


As said above - use the session instead.

> Input Form php:
> $ERRORS = array();
> $ERRORS = $_GET['errors']


There's a ';' missing at the EOL (this causes the error you mentioned
below).

Just a naming hint: Variables should not be named all uppercase (except
for the predefined superglobal arrays). Such names should be reserved
for constants. The most common style looks like this:

myNiceFunction()
$myNiceVariable
MY_NICE_CONSTANT

> if (sizeof($ERRORS) > 0) {


if (!empty($_SESSION['errors'])) {

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


The Location URI must be absolute including scheme and hostname. This is
required by the HTTP spec:

header("Location: http://$_SERVER[HTTP_HOST]/input.form.php ...");

But I'm still not sure why you would need this redirect. The entire
handling of a form (validation, processing) can be done on a single
page. Only if the processing succeeds, you might want to redirect to
some result page.

Micha
Reply With Quote
  #3 (permalink)  
Old 04-13-2008, 02:51 AM
patricktr
 
Posts: n/a
Diggs:
Default Re: Can you pass an array URL variable

Hi Micha,

Thanks a lot - all good stuff.

PS1. For my branching 'header' line I am just quoting the name of the php I
want to go to and it's working ok for me .... what does this mean?
PS2. Yes I'm sure I am missing a trick using two routines instead of one but I
tried for a while and I couldn't see how to do it in one place... I'll continue
to try. By screen I mean the page that the end user is presented with. There
are effectively 2 pages (it's a multi part form); page one iterates until it
passes validation checks and then page 2 kicks in. When that page is validated,
I update a db with info from both pages.
Regards.
Patrick.

Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 09:01 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk