PHP Classes

SELECT input not working

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Upcoming Visual HTML ...  >  All threads  >  SELECT input not working  >  (Un) Subscribe thread alerts  
Subject:SELECT input not working
Summary:SELECT input value not coming back from form
Messages:4
Author:Ian Holden
Date:2008-05-09 19:31:02
Update:2008-05-12 15:38:13
 

  1. SELECT input not working   Reply   Report abuse  
Picture of Ian Holden Ian Holden - 2008-05-09 19:31:02
I have a form input that is a SELECT type defined as follows:

$form->AddInput( array(
"TYPE" => "select",
"NAME" => "EngCatID",
"ID" => "EngCatID",
"VALUE" => $SecRequest->EngCatID,
"OPTIONS" => array( "1" => "DESIGN", "2" => "ENTERPRISE", "3" => "LAB" ),
"ValidateAsNotEmpty" => 1,
"DiscardInvalidValues" => 1,
"ValidationErrorMessage" => "Not a valid Engineering Category value",
"LABEL" => "<u>E</u>ngineering Category",
"ACCESSKEY" => "E"
));

The form is displaying fine intially - this input has the correct value showing for the existing information. But when the form is submitted, I cannot get the value for this input. The following code fragment:

/*
* Load form input values eventually from the submitted form.
*/
$form->LoadInputValues( $form->WasSubmitted() );

# ... Empty the array that will list the values with invalid field after validation
$verify = array();

# ... Check if the global array variable corresponding to hidden input field is defined, meaning that the form was submitted as opposed to being displayed for the first time
writeDevLogEntry( "reqform_gen2.php => ".$form->WasSubmitted() );
if ($form->WasSubmitted( "Action" )) {

# ... Therefore we need to validate the submitted form values
if(($error_message = $form->Validate( $verify )) == "") {

# ... It's valid, set the flag to tell the form it is ready to be processed
print "EngCatID submitted value is ".$form->GetInputValue( "EngCatID" )."<br>\n";
getFormContents();
$doit = 1;

}

The call to GetInputValue with "EngCatID" returns with "EngCatID submitted value is EngCatID: it was not specified a valid input". If I use phpinfo() to see what is being POSTED from the form, $_POST['EngCatID'] has the value I expect.

I have another SELECT on the form that works right, but this (and others very similar to it) all don't work the same. What, probably basic, concept am I missing?

Hope I provided enough details to see what others might be able to offer as guidance.

  2. Re: SELECT input not working   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-05-10 01:31:01 - In reply to message 1 from Ian Holden
That means that for some reason the AddInput call for that select did not succeed. You may want to check its return value, but I suspect that it fails because you are not passing a valid VALUE parameter.

  3. Re: SELECT input not working   Reply   Report abuse  
Picture of Ian Holden Ian Holden - 2008-05-12 15:30:31 - In reply to message 2 from Manuel Lemos
I'll try that (though the form displays fine, without error messages) and only has an issue when I try to see the submission results. The field is showing the correct value for the field upon initial loading.

Now, I think I may have found the issue - if I change the options from numeric indices to character indices, the input is fine following submission.

So when I change the OPTIONS entry to
"OPTIONS" => array( "A" => "DESIGN", "B" => "ENTERPRISE", "C" => "LAB" ),

when the form is submitted I'm able to get the submitted value of "A", "B", or "C". But it won't give me a numeric like value (e.g. "1", "2", or "3").

  4. Re: SELECT input not working   Reply   Report abuse  
Picture of Ian Holden Ian Holden - 2008-05-12 15:38:13 - In reply to message 2 from Manuel Lemos
Thanks - you were right -- I wasn't checking the AddInput return value (assuming that if the form displayed without issues, the call must be fine). When I check the return code, though, it tells me it has a problem with the input. I'll debug that a bit more.

My bad for "assuming" and not checking return values. I think this plus my OPTIONS entry item I also discovered is probably going to get me working again.

BTW, this is a mighty fine class - powerful, very powerful. Thanks for authoring it.