PHP Classes

SetSelectOptions usage

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  >  Locating addresses on...  >  All threads  >  SetSelectOptions usage  >  (Un) Subscribe thread alerts  
Subject:SetSelectOptions usage
Summary:what is the proper way to use it?
Messages:5
Author:simon virtič
Date:2007-05-07 08:41:46
Update:2007-05-08 07:19:49
 

  1. SetSelectOptions usage   Reply   Report abuse  
Picture of simon virtič simon virtič - 2007-05-07 08:41:46
Hi!

I would like to know what is the proper way to use function SetSelectOptions...

When I use it like this:
$error = $form->SetSelectOptions("gsmType",$gsmTypesArray,array(""));
I get data in $_POST variable, but I cannot use GetInputValue function to retrieve data...
Is the idea of using GetInputValue to retrieve data in this case the right way or not???

Detailed description:
Our framework is divided into request, bussines logic and templates. Therefore is cannot use AddInput function to edit data from database
(in the moment of "initiating" $form I don't know what the real data in my database are, because this comes latter in bussines logic -> where I set proper data with SetSelectOptions or SetInputValue functions. When I use SetInputValue with <input type="text"> I use GetInputValue function to retrieve data. But when I use SetSelectOptions function, data is missing (tried to use function GetSubmittedValue but it fails too).

example code (SetInputValue ):

$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"description",
"ID"=>"description",
"MAXLENGTH"=>100,
"ValidateAsNotEmpty"=>1,
"ValidationErrorMessage"=>"Vnesi opis",
"Capitalization"=>"lowercase",
"LABEL"=>"<u>D</u>escription",
"ACCESSKEY"=>"D"
));

//later in bussines logic:
$form->SetInputValue("description",$description);

//after the form is submitted:
$description = $form->GetInputValue("description");

//EVERYTHING IS FINE
---------------------
example code (SetSelectOptions ):

$gsmTypesArray=array(""=>"Choose gsm");

SMSForms::$form->AddInput(array(
"TYPE"=>"select",
"ID"=>"gsmType",
"NAME"=>"gsmType",
"LABEL"=>"<u>G</u>sm",
"ACCESSKEY"=>"G",
"VALUE"=>"",
"OPTIONS"=>$gsmTypesArray,
//"ValidateAsNotEmpty"=>1,
//"ValidationErrorMessage"=>"Choose gsm type"
));

//later in bussines logic:
// $mimeTypesArray is data from database and is set right

$form->SetSelectOptions("gsmType",$mimeTypesArray,array(""));

//after the form is submitted:
$gsmType = $form->GetInputValue("gsmType");

$gsmType is empty (I can retrieve data with $_POST["gsmType"] + if i turn on validation ValidateAsNotEmpty, I get error message even when the field is not empty)...

Please help
Simon

  2. Re: SetSelectOptions usage   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-07 14:26:20 - In reply to message 1 from simon virti&#269;
For simple select values, the value to pass as selected value must be a string, integer or double, not an array.

In any case, always check the return value of SetSelectOptions function as it returns an error value.

  3. Re: SetSelectOptions usage   Reply   Report abuse  
Picture of simon virti&#269; simon virti&#269; - 2007-05-07 14:55:58 - In reply to message 2 from Manuel Lemos
Hey!

So instead of
$form->SetSelectOptions("gsmType",$mimeTypesArray,array(""));

I should use something like:
$form->SetSelectOptions("gsmType",$mimeTypesArray,0);

???

but in this case I get error:
gsmType: it was not specified an array with a single selected value

???

thanx
Simon

  4. Re: SetSelectOptions usage   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-07 21:21:01 - In reply to message 3 from simon virti&#269;
Yes, you are right, I was looking at the wrong part of the class.

From what you describe, it seems the LoadInputValues function is not being called or is being called at the wrong place. Make sure that function is always called after the SetSelectOptions function call.

  5. Re: SetSelectOptions usage   Reply   Report abuse  
Picture of simon virti&#269; simon virti&#269; - 2007-05-08 07:19:49 - In reply to message 4 from Manuel Lemos
Thanx Manuel!

It works now!!!

The thing I didn't understand is that SetSelectOptions must be called before LoadInputValues and SetInputValue after LoadInputValues.

I called both functions before LoadInputValues...

Thanx once again!
Simon