Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:27:13+00:00 2026-06-04T13:27:13+00:00

I have some problems to find the solution by myself, that’s why I ask

  • 0

I have some problems to find the solution by myself, that’s why I ask the community.
I am developping an app with Zend Framework.

I have a form, with some SELECT Elements. Some of them are populated with data from the DB, and some others with data inside the form ( ->addMultiOption(0, ‘Option 1’)…).

The insert works well, but I have some troubles with the update function. The SELECT elements filled with the options inside the form are populated with success, but the SELECT elements filled with the DB data are not setted correctly. The first option of the table of the DB is always selected.

So I guess there’s something wrong in my code. I deleted some elements for better visibility.

My Form:

<?php

class Application_Form_Pda extends Zend_Form
{

public function init()
{
    $this->setName('ajouter');


    $addFabForm = new Zend_Form;
    $addFabForm->setAction('#');            // A compléter
    $addFabForm->setMethod('post');
    $addFabForm->setAttrib('id', '');       // A compléter

    //Id
    $id = new Zend_Form_Element_Hidden('PDA_ID');
    $id->addFilter('Int');

    //Select du Fabriquant
    $nomFabriquant = new Zend_Form_Element_Select('FAB_NOM');
    $nomFabriquant  ->setLabel('Fabriquant')
                    ->setRequired(true)
                    ->addErrorMessage('Vous devez sélectionner un fabriquant');

    $TableFab = new Application_Model_DbTable_Fabriquant();
    //$nomFabriquant->addMultiOption(0, "");
    foreach ($TableFab->fetchAll() as $ind) {
        $nomFabriquant->addMultiOption($ind['FAB_ID'], $ind['FAB_NOM']);
    }

    // Select du Modèle
    $nomModele = new Zend_Form_Element_Select('MOD_NOM');
    $nomModele      ->setLabel('Modèle')
                    ->setRequired(true)
                    ->addErrorMessage('Vous devez sélectionner un modèle');

    $TableMod = new Application_Model_DbTable_Modele();
    //$nomModele->addMultiOption(0, "");
    foreach ($TableMod->fetchAll() as $ind) {
        $nomModele  ->addMultiOption($ind->MOD_ID, $ind->MOD_NOM);
    }

    // Champs texte, numéro IMEI
    $imei = new Zend_Form_Element_Text('PDA_IMEI');
    $imei           ->setRequired(true)
                    ->setLabel('IMEI')
                    ->addFilter('StripTags')
                    /*->addValidator('Default_Validator_Imei')*/
                    ->addValidator('NotEmpty');

    // Select du Site
    $nomSite = new Zend_Form_Element_Select('PDA_SITE');
    $nomSite        ->setLabel('Site')
                    ->setRequired(true)
                    ->addMultiOption(0, "Nantes")
                    ->addMultiOption(1, "Paris")
                    ->addErrorMessage('Vous devez sélectionner un site');

    // Achat DSIV
    $dsiv = new Zend_Form_Element_Checkbox('PDA_ACHATDSIV');
    $dsiv           ->setChecked(true)
                    ->setLabel('Achat SVSI');

    // Checkbox boite
    $boite = new Zend_Form_Element_Checkbox('PDA_OPT_BOITE');
    $boite          ->setChecked(true)
                    ->setLabel('Boite');

    // Checkbox USB
    $usb = new Zend_Form_Element_Checkbox('PDA_OPT_USB');
    $usb            ->setChecked(true)
                    ->setLabel('Cable USB');

    // Checkbox chargeur
    $chargeur = new Zend_Form_Element_Checkbox('PDA_OPT_CHARGEUR');
    $chargeur       ->setChecked(true)
                    ->setLabel('Chargeur');

    // Checkbox casque
    $casque = new Zend_Form_Element_Checkbox('PDA_OPT_CASQUE');
    $casque         ->setChecked(true)
                    ->setLabel('Casque');

    // Checkbox batterie
    $bat = new Zend_Form_Element_Checkbox('PDA_OPT_BATTERIE');
    $bat            ->setChecked(true)
                    ->setLabel('Batterie');

    // Checkbox filaire
    $fil = new Zend_Form_Element_Checkbox('PDA_OPT_FILAIRE');
    $fil            ->setChecked(true)
                    ->setLabel('Filaire');

    // Select de l'état
    $etat = new Zend_Form_Element_Select('PDA_ETAT');
    $etat       ->setLabel('Etat')
                    ->setRequired(true)
                    ->addMultiOption(0, "Stock")
                    ->addMultiOption(1, "En prêt")
                    ->addMultiOption(2, "SAV")
                    ->addMultiOption(3, "Sorti du parc")
                    ->setValue('Stock')
                    ->setLabel('Etat')
                    ->addErrorMessage('Vous devez sélectionner un état');

    $validPda = new Zend_Form_Element_Submit('envoyer');
    $validPda       ->setAttrib('id', 'boutonenvoyer');

    $this->addElements(array($id, $nomFabriquant, $nomModele, $imei, $nomSite, $dsiv, $boite, $usb, $chargeur, $casque, $bat, $fil, $etat, $validPda));
}


}

My Controller:

<?php

    $form = new Application_Form_Pda();                  //Création du formulaire
    $form->envoyer->setLabel('Modifier');                       // Ajout d'un libellé au bouton d'envoi
    $this->view->form = $form;                                  // Envoi du formulaire à la vue
    if ($this->getRequest()->isPost()) {                        // si la méthode isPost de l'objet Request renvoi True, le formulaire à été envoyé
        $formData = $this->getRequest()->getPost();             // Récupération des données avec la méthode getPost()
        if ($form->isValid($formData)) {                        // Vérification de ces données avec la méthode isValid()
            $id = (int)$form->getValue('PDA_ID');               // Récupération de l'ID du fabriquant
            $idModele       = $form->getValue('MOD_NOM');
            $imei           = $form->getValue('PDA_IMEI');
            $nomSite        = $form->getValue('PDA_SITE');
            $dsiv           = $form->getValue('PDA_ACHATDSIV');
            $boite          = $form->getValue('PDA_OPT_BOITE');
            $usb            = $form->getValue('PDA_OPT_USB');
            $chargeur       = $form->getValue('PDA_OPT_CHARGEUR');
            $casque         = $form->getValue('PDA_OPT_CASQUE');
            $bat            = $form->getValue('PDA_OPT_BATTERIE');
            $fil            = $form->getValue('PDA_OPT_FILAIRE');
            $etat           = $form->getValue('PDA_ETAT');
            $pda = new Application_Model_DbTable_Pda();     // On créé un nouvel enregistrement
            $pda->modifierPda($id, $idModele, $imei, $dsiv, $boite, $usb, $chargeur, $casque, $bat, $fil, $nomSite, $etat);     // On affecte à cet enregistrement le nom du fabriquant, et on persiste en BDD
            $this->_helper->redirector('index');                // pour finir, on redirige vers index de Fabriquant
        } else {
            $form->populate($formData);                         // Si la validation n'est pas passée, on réaffiche les données dans le formulaire
        }
    }
    else {
            $id = $this->_getParam('id', 0);
            //var_dump($id);
            if ($id > 0) {
                $pda = new Application_Model_DbTable_Pda();
                $formData2 = $pda->getPda($id);
                //echo "L'ID est : " . $id;     // Vérification
                $form->populate($formData2);
            } else {
                echo "Information : nous sommes dans le else de modifierAction de PdaController.php";
                echo "L'ID est : " . $id;
            }
        }

The Model:

<?php

class Application_Model_DbTable_Pda extends Zend_Db_Table_Abstract
{

protected $_name = 'pda';
protected $_primary = 'PDA_ID';     // La primary key



public function getPda($id){
    $id = (int)$id;
    $row = $this->fetchRow('PDA_ID = ' . $id);
    if (!$row) {
        throw new Exception("Impossible de trouver la ligne $id");
    }
    return $row->toArray();
}


public function ajouterPda($idModele, $imei, $dsiv, $boite, $usb, $chargeur, $casque, $bat, $fil, $nomSite, $etat) {
    $idModele = (int)$idModele;
    $data = array(
            'MOD_ID'            => $idModele,
            'PDA_IMEI'          => $imei,
            'PDA_ACHATDSIV'     => $dsiv,
            'PDA_OPT_BOITE'     => $boite,
            'PDA_OPT_USB'       => $usb,
            'PDA_OPT_CHARGEUR'  => $chargeur,
            'PDA_OPT_CASQUE'    => $casque,
            'PDA_OPT_BATTERIE'  => $bat,
            'PDA_OPT_FILAIRE'   => $fil,
            'PDA_SITE'          => $nomSite,
            'PDA_ETAT'          => $etat
    );
    $this->insert($data);
}

public function modifierPda($id, $idModele, $imei, $dsiv, $boite, $usb, $chargeur, $casque, $bat, $fil, $nomSite, $etat) {
    $id = (int)$id;
    $idModele = (int)$idModele;
    $data = array(
            'MOD_ID'            => $idModele,
            'PDA_IMEI'          => $imei,
            'PDA_ACHATDSIV'     => $dsiv,
            'PDA_OPT_BOITE'     => $boite,
            'PDA_OPT_USB'       => $usb,
            'PDA_OPT_CHARGEUR'  => $chargeur,
            'PDA_OPT_CASQUE'    => $casque,
            'PDA_OPT_BATTERIE'  => $bat,
            'PDA_OPT_FILAIRE'   => $fil,
            'PDA_SITE'          => $nomSite,
            'PDA_ETAT'          => $etat
    );
    $this->update($data, 'PDA_ID = ' . $id);
}

public function supprimerFabriquant($id) {
    $this->delete('PDA_ID = ' . (int)$id);
}


}

The id of the ‘Modèle’ is good in the DB, but the element doesn’t fill with the DB value… Any idea?

Thanks a lot for your help! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:27:15+00:00Added an answer on June 4, 2026 at 1:27 pm

    It looks to me like FAB_NOM will not populate correctly because you don’t seem to be passing the value from your DB table.

    Also ‘MOD_NOMlikes like it will work if you rename it toMOD_ID`.

    //no data present to reference to FAB_NOM and MOD_ID is present but MOD_NOM is not    
    $data = array(
                    'MOD_ID'            => $idModele,
                    'PDA_IMEI'          => $imei,
                    'PDA_ACHATDSIV'     => $dsiv,
                    'PDA_OPT_BOITE'     => $boite,
                    'PDA_OPT_USB'       => $usb,
                    'PDA_OPT_CHARGEUR'  => $chargeur,
                    'PDA_OPT_CASQUE'    => $casque,
                    'PDA_OPT_BATTERIE'  => $bat,
                    'PDA_OPT_FILAIRE'   => $fil,
                    'PDA_SITE'          => $nomSite,
                    'PDA_ETAT'          => $etat
            );
    

    In order for populate() to work correctly you need to have some data that the form recognizes as belonging to an element. Usually we accomplish this by naming our form elements the same as the columns we want to populate in our database.

    Currently the select elements you are having problems with do not seem to have a column of the same name associated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problems sending an id though jquery. I have a form select
I have some problems with a java app i'm developing, i'm using HtmlCleaner 2.2
I'm Using CakePHPs standard Auth mechanism, but I have some problems with that. Everytime
I find myself in a situation that someone else must have got stuck in
I have some problems sending mails through SMTP using Spring's MailSender interface and the
I have some problems with OpenCV s cvCanny(...) and the Image data types it
i have some problems with rowspan: var doc1 = new Document(); doc1.SetPageSize(PageSize.A4.Rotate()); string path
I have some problems with mod_rewrited at .httacess. We have created a website, the
I have some problems to start programming using cocos2D on linux + android. I
I have some problems with controlling a while loop inside an event structure. Say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.