What I have is an issue with posting forms with Dynamic ListBoxes.
What happens is when you fill the form out, and hit submit, it validates the
form .. if there is a required field not filled out, it comes back and gives
an error. All the textfields have all the information and the Static
ListBoxes have all the information they filled out... But if the user
selected a STATE (which is pulled dynamically) it will reset this box to the
default setting.

The dynamic listboxes are pulling great just not grabbing what user selected
on post if an error occurs.

Hope that makes sense.

********************
The File that makes the list boxes
Listboxes.php
***************************

function build_states_tree(&$output, &$preselected) {

        $qid = db_query("SELECT id, name FROM states ORDER BY name ASC");

        while ($man =  db_fetch_object($qid)) {
                $selected = in_array($man->id, $preselected) ? "selected" :
"";
                $output .= "<option value=\"" . ov($man->id) . "\"
$selected>" . ov($man->name) . "</option>";
        }       
}


*********************
I have a script
SIGNUP.PHP -- Notice I have shortened a lot of this.
*****************************************

/* form has been submitted, try to create the new user account */
if (match_referer() && isset($HTTP_POST_VARS)) {
        $frm = $HTTP_POST_VARS;
        $errormsg = validate_form($frm, $errors);

        if (empty($errormsg)) {

                adduser_info($frm);
                adduser_ins($file, $frm);

                $DOC_TITLE = "Webspyder's Signup Successful";
                include("$CFG->templatedir/signup_header.php");
                include("$CFG->templatedir/signup_success.php");
                include("$CFG->templatedir/signup_footer.php");
                die;            

        }
}

$DOC_TITLE = "Webspyder's Signup Page";
include("$CFG->templatedir/signup_header.php");

        /* build array for each seperate listbox */
                $frm["states"] = array();
                $frm["services"] = array();
                $frm["phonenumbers"] = array();
                $frm["payments"] = array();
                $frm["hear"] = array();

        /* build the categories listbox options, preselect the top item */
                build_states_tree($states_options, $frm["states"]);
                build_services_tree($services_options, $frm["services"]);
                build_phonenumbers_tree($phonenumbers_options,
$frm["phonenumbers"]);
                build_payments_tree($payments_options, $frm["payments"]);
                build_hear_tree($hear_options, $frm["hear"]);

        
include("templates/signup_form.php");
include("$CFG->templatedir/signup_footer.php");

/***************************************************************************
***
 * FUNCTIONS
 
****************************************************************************
*/

function validate_form(&$frm, &$errors) {
/* validate the signup form, and return the error messages in a string.  if
 * the string is empty, then there are no errors */

        $errors = new Object;
        $msg = "";
        
        if (username_exists($frm["username"])) {
                $errors->username = true;
                $msg .= "<li>The username <b>" . ov($frm["username"]) ."</b>
is already in use. Please select another username and try again.";
        }

        for ($i = 0; $i < count($frm["states"]); $i++) {
                if (empty($frm["states"][$i])) {
                        $errors->state = true;
                        $msg .= "<li>You must select your state!";
                }
        }

        }
        
        return $msg;
}



function adduser_info($frm) {
// Information added by user inserted into the Customer Database

ETC....ETC... ETC.....



*********************************
And a templates SIGNUP_FORM.PHP
***********************************************************
FORM CODE
<form name=signupform method=post action=https://***.com/signup.php>



SELECT STATE BOX
<select name="states[]">
<option value="" selected>Please Select State</option>
<?=$states_options?>
</select>
<?err($errors->state)?>



--
Kacey A. Murphy
Digitalicom Technologies
Office: 864.582.5269
Cell: 864.266.7701
Email: [EMAIL PROTECTED]
Web: http://www.digitalicom.com


****************************************************
This e-mail is intended for the recipient only and may contain confidential
information. If you are not the intended recipient then you should reply to
the sender and take no further ation based upon the content of the message.
Internet e-mails are not necessarily secure. Digitalicom and/or Kacey A.
Murphy does not accept any responsibility for changes made to this message.
Although checks have been made to ensure this message and any attchments are
free from viruses the recipient should ensure that this is the case.

-----Original Message-----
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 16, 2004 4:47 AM
To: 'Luke'; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP Includes and Echoes in Head Sections and Search
Engines

On 15 January 2004 22:39, Luke wrote:

> ? Holy cow, this gets simpler all the time. Pretty soon, there'll be
> ? nothing left on my page but PHP includes and echo functions! ?
> ? Does this cut down on a website's file size? In other
> words, are the php
> ? includes effectively inactive when no one's viewing your main pages,
> ? leaving them empty of the included pages?
> 
> Well in a way yes, it wont cut down the transfer bandwitdth,
> but because you
> are reusing the same files over again, this will take up less
> disk space on
> your
> server. But the same amount of data is transferred when a
> user views the
> page (as you can see from view->source)
> 
> ? But suppose there's a certain page where I don't want the
> style sheet in
> ? the middle - the one I named MIDDLE. Is there a way to mark
> it in the
> ? include page, then instruct the main page to either not import it or
> ? replace it with nothing ("")?
> 
> youd have to use a variable, so in the main page do the following
> 
> if($pagetoshow == 'withoutmiddle'){
>     $includemiddle = FALSE;
> }else{
>     $includemiddle = TRUE; //(or false depending)
> }

Euch! Very long-winded and inefficient.  Much better is:

   $includemiddle = $pagetoshow!='withoutmiddle';

> 
> and in the include do this:
> 
> if($includemiddle == TRUE){

Likewise -- this can be written more efficiently and more readbly as simply:

   if ($includemiddle)

(Since $includemiddle will be TRUE or FALSE, you can use it directly in the
if () -- retrieving its value and  comparing it against TRUE gives TRUE if
$includemiddle is, er, TRUE, and FALSE if it's FALSE, so doing the
comparison just wastes CPU time to reproduce the value you first thought
of.)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to