2009年11月19日星期四

Re: [fw-mvc] Re: problem with zend_formElemend_Select

Thanks for your reaction

I already found out what the problem was.
In the view was already a hard coded form which was interferring.
I removed that form and all went well.



On Thu, Nov 19, 2009 at 9:18 AM, Michelangelo van Dam <michelangelo+zf_all@dragonbe.com> wrote:
Hi Jigal,

Have you tried the following ?

$genresList = array (
'electronic' => 'Electronic',
        'country' => 'Country',
        // … fill it up with your selection here
);

$genres = new Zend_Form_Element_Select('genres');
$genres->setLabel('Genre')
               ->setRequired(true)
               ->setMultiOptions($genresList);

$form->addElement($genres);

This should do the trick.

Good luck,

Michelangelo

On 17 Nov 2009, at 22:14, Jigal sanders wrote:

This whole example from the book beginning zend framework seems not to be working:

/**
* Create Add Artist Form.
*
* @return Zend_Form
*/
private function getAddArtistForm()
{

   $form = new Zend_Form();
   $form->setAction("saveArtist");
   $form->setMethod("post");
   $form->setName("addartist");

   //Create artist name text field.
   $artistNameElement = new Zend_Form_Element_Text('artistName');
   $artistNameElement->setLabel("Artist Name:");

   //Create genres select menu
   $genres = array("multiOptions" => array
   (
       "electronic"         => "Electronic",
       "country"             => "Country",
       "rock"                  => "Rock",
       "r_n_b"               => "R & B",
       "hip_hop"            => "Hip-Hop",
       "heavy_metal"      => "Heavy-Metal",
       "alternative_rock" => "Alternative Rock",
       "christian"             => "Christian",
       "jazz"                   => "Jazz",
       "pop"                    => "Pop"
     ));

   $genreElement = new Zend_Form_Element_Select('genre', $genres);
   $genreElement->setLabel("Genre:");
   $genreElement->setRequired(true);

   //Create favorite radio buttons.
   $favoriteOptions = array("multiOptions" => array
   (
       "1" => "yes",
       "0" => "no"
   ));


   $isFavoriteListElement = new Zend_Form_Element_Radio('isFavorite',
                                            $favoriteOptions);
   $isFavoriteListElement->setLabel("Add to Favorite List:");
   $isFavoriteListElement->setRequired(true);

   //Create Rating raio button
   $ratingOptions = array("multiOptions" => array
    (
       "1" => "1",
       "2" => "2",
       "3" => "3",
       "4" => "4",
       "5" => "5"
   ));

   $ratingElement = new Zend_Form_Element_Radio('rating', $ratingOptions);
   $ratingElement->setLabel("Rating:");
   $ratingElement->setRequired(true)->addValidator(new Zend_Validate_Alnum(false));

   //Create submit button
   $submitButton = new Zend_Form_Element_Submit("submit");
   $submitButton->setLabel("Add Artist");

   //Add Elements to form
   $form->addElement($artistNameElement);
   $form->addElement($genreElement);
   $form->addElement($isFavoriteListElement);
   $form->addElement($ratingElement);
   $form->addElement($submitButton);

   return $form;

}

It shows all items twice and inconsistent labels and it also doesn't fill the select box.

On Tue, Nov 17, 2009 at 5:30 PM, Jigal sanders <jigalroecha@gmail.com> wrote:
Hello overyone.

I'm trying to fill a  Zend_Form_Element_Select box with an array but it stays empty on the screen.
This is my code:

// create artist name text field
$artistNameElement = new Zend_Form_Element_Text('artistName');
$artistNameElement->setLabel("Artist name: ");
$genres = array("multiOptions" => array(
"electronic" =>"Electronic", 
"country" => "Country",
"rock" =>"Rock", 
"r_n_b" =>"R & B", 
"hip_hop" => "Hip-Hop",
"heavy_metal" =>"Heavy-Metal",
"alternative_rock" =>"Alternative Rock", 
"jazz" =>"Jazz", 
"pop" =>"Pop"
));
$genreElement = new Zend_Form_Element_Select('genre', $genres);
$genreElement->setLabel("Genre:");
$genreElement->setRequired(true);

What is going wrong?

Thanks,

j sanders



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489




--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489

没有评论: