Error with edit button after add a wherecondition

Error with edit button after add a wherecondition

WININFOWININFO Posts: 19Questions: 2Answers: 0
edited March 2021 in Free community support

Hi, I have an error when I update my table with a edit button, my json data is empty, but i update with a setValue in editor.

My controller :

```
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST

$today = date("Y-m-d H:i:s");

$editor = Editor::inst( $db, 'llx_commandedet as comdet', 'rowid')
->fields(
    Field::inst('com.rowid'),
    Field::inst('p.ref'),
    Field::inst('comdet.date_start')
        ->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) ),
    Field::inst('com.ref'),
    Field::inst('soc.nom'), 
    Field::inst('p.label'),
    Field::inst('comdetex.kit_specifique')
        ->getFormatter( function ( $val, $data ) {
            return $val ? 'Oui': 'Non';
        }),
    Field::inst('comdetex.date_retrait', 'date_retrait')
        ->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) )
        ->set(Field::SET_EDIT)
        ->setValue($today),
    Field::inst('comdetex.fk_statut', 'statut')
        ->set( Field::SET_EDIT )
        ->setValue("3"),
    Field::inst('comex.id_site', 'id_site'),
)
->leftJoin('llx_commande as com','com.rowid', '=', 'comdet.fk_commande')
->leftJoin('llx_commande_extrafields as comex','comex.fk_object', '=', 'com.rowid')
->leftJoin('llx_commandedet_extrafields as comdetex','comdetex.fk_object', '=', 'comdet.rowid')
->leftJoin('llx_societe as soc','soc.rowid', '=', 'com.fk_soc')
->leftJoin('llx_societe as point_relais','point_relais.rowid', '=', 'comex.fk_point_relais')
->leftJoin('llx_product as p','p.rowid', '=', 'comdet.fk_product')
->where('com.fk_soc', $user->id)
->where('comdetex.date_retrait', null)
->where('comex.id_site', $_POST['id_site'])
->process( $_POST )
->json();
And my table : 


if ($_SERVER["REQUEST_METHOD"] == "POST" ) {
    $id_site = $_POST["id_site"]; 
}
<?php > ?>
var editor;
$(document).ready( function () {


    editor = new $.fn.dataTable.Editor( {
        language: {
            url:"https://cdn.datatables.net/plug-ins/1.10.22/i18n/French.json"
        },
        ajax: {
            url: '../../includes/datatable/controllers/point_relais.php',
            type:'POST',
            data: function (d) {
                d.id_site = "<?= $id_site ?>";
            }
        },
        table: '#commande',
        i18n: {
            create: {
                button: "Nouveau",
                title:  "Créer nouvelle entrée",
                submit: "Créer"
            },
            edit: {
                button: "Modifier",
                title:  "Êtes vous sur de vouloir mettre à jour le statut de la commande?",
                submit: "Confirmer"
            },
            remove: {
                button: "Supprimer",
                title:  "Supprimer",
                submit: "Supprimer",
                confirm: {
                    _: "Etes-vous sûr de vouloir supprimer %d lignes?",
                    1: "Etes-vous sûr de vouloir supprimer 1 ligne?"
                }
            },
            error: {
                system: "Une erreur s’est produite, contacter   l’administrateur système"
            },
            multi: {
                title: "Plusieurs valeurs",
                info: "Les éléments sélectionnés contiennent des valeurs différentes pour cette entrée. Pour modifier et mettre tous les éléments pour cette entrée pour la même valeur, cliquez ou appuyez ici, sinon ils vont conserver leurs valeurs individuelles.",
                restore: "Annuler les modifications"
            },
            datetime: {
                previous: 'Précédent',
                next:     'Premier',
                months:   [ 'Janvier', 'Février', 'Mars', 'Avril', 'peut', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' ],
                weekdays: [ 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam' ]
            }
        },
        fields: [
            // {
            //     label: "Date retrait",
            //     name:"date_retrait",
            //     data:"date_retrait",
            //     type:"date",
            // }
        ],
    });

    var table = $('#commande').DataTable({
        language: {
            url:"https://cdn.datatables.net/plug-ins/1.10.22/i18n/French.json"
        },
        ajax: {
            url: '../../includes/datatable/controllers/point_relais.php',
            type:'POST',
            data: function (d) {
                d.id_site = "<?= $id_site ?>";
            }
        },
        pageLength: 20,
        dom : 'BPirt',
        columns: [
            {targets: 0,
            data: null,
            defaultContent: '',
            orderable: false,
            className: 'select-checkbox' },
            {data: 'p.ref'},
            {data: 'comdet.date_start'},
            {data: 'p.label'},
            {data: 'id_site', className:"id_site", visible:false},
        ],  

        select: {
            style:    'multi',
            selector: 'td:first-child'
        },
        order: [[ 2, 'desc' ]],
        responsive:true,
        buttons: [{  extend: "edit",   editor: editor, text: "Valider Commande(s) retirée(s)"}]
    });

        // $('#id_site').on( 'keyup', function () {
        //     table
        //         .columns(".id_site")
        //         .search( this.value )
        //         .draw();

        // } );
} );

</script>

<?php
if(!empty($_POST['id_site'])){

<?php > ?> </tfoot> </table> <?php } ?> < script> ``` Thanks
Article Date Prévisionnelle Produit Site

Replies

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Just to confirm, if you remove the:

    ->where('com.fk_soc', $user->id)
    ->where('comdetex.date_retrait', null)
    ->where('comex.id_site', $_POST['id_site'])
    

    then you don't get any errors?

    What version of the Editor PHP libraries are you using please (so I can check the line numbers)?

    Allan

  • WININFOWININFO Posts: 19Questions: 2Answers: 0

    Hi,

    Sorry for the time. Yes I haven't any errors.

    I use the Editor 1.9.6

    Clement

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Those errors are all where Editor tries to access the data sent by the client-side.

    Could you possibly try:

    ->where( function ($q) {
      $q->where('com.fk_soc', $user->id);
      $q->where('comdetex.date_retrait', null);
      $q->where('comex.id_site', $_POST['id_site']);
    } )
    

    instead of your three ->where() lines please?

    I don't really know if that will resolve it, but equally, to be honest, I don't know why those three lines would disrupt the $_POST data!

    Regards,
    Allan

  • WININFOWININFO Posts: 19Questions: 2Answers: 0

    I try but i have a json invalid error

    Clement

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Hi Clement,

    Sorry, you'll need:

    ->where( function ($q) use ($user) {
    

    I always forget that in PHP...!

    Allan

  • WININFOWININFO Posts: 19Questions: 2Answers: 0

    I have the same error "Need to contact an administrator ..

    Thank's aniway

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Are you able to link to your page so we can take a look, please?

    Colin

  • WININFOWININFO Posts: 19Questions: 2Answers: 0

    I can't, it's a customer area, with password access, sorry ...

    Clement

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    What is the response from the server - does it contain an error message saying what the problem is? I might have missed some other daft syntax error...

    Allan

This discussion has been closed.