Query in chronoforms joomla not works

246 Views Asked by At

I have a table named "folder" that contains all client files. when I click "Edit" button: I want to compare the field "EtatDemande" which is registered in the database by "EtatDemande" that I change ($ _ POST [ 'EtatDemande']) if yes the field "StateChanged" receives "1"

I try the following query but if I put after "DBSAVE" after the registration of the modification the 2 values are always the same.

If I put before the "EtatDemande" field which is registered in the database always empty

 <?php 
  /****this query just for display the old field(registration data base *****/  
    $db = JFactory::getDbo();
    $db1 = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query1 = $db1->getQuery(true);

    $query1->select($db1->quoteName(array('EtatDemande')));
    $query1->from($db1->quoteName('ml0ak_chronoengine_chronoforms_datatable_formulaire'));
    $query1->where( $db1->quoteName('NuméroK10') . ' = ' . $db1->quote($_POST['NuméroK10']));

    $db1->setQuery($query1);
    $results = $db1->loadObjectList();

    foreach ( $results as $us) {
        $EtatDemande=$us->EtatDemande;
    }

    echo "   ****   Etat Demande ancien ".$EtatDemande;
    $result1 = $db1->execute();

    /*********************************************************/

       $fields = array(
        $db->quoteName('EtatChanged') . ' = ' . $db->quote(1),
    );     
    $conditions = array( 
     $db->quoteName('EtatDemande') . '= ' . $db->quote($_POST['EtatDemande']),
     $db->quoteName('NuméroK10') . ' = ' . $db->quote($_POST['NuméroK10'])
    );

    echo "EtatDemande   :".$_POST['EtatDemande'];

    $query->update($db->quoteName('ml0ak_chronoengine_chronoforms_datatable_formulaire'));
    $query->set($fields);
    $query->where($conditions);

    $db->setQuery($query);
    $result = $db->execute();
    ?>
1

There are 1 best solutions below

0
Sloan Thrasher On

Keep in mind that Chronoforms saves the fields from the form without you having to do anything. It may be overwriting your changes. Instead of doing the update in code, maybe you should try changing the value in the $form->data array.