Query database before "final" submit

Query database before "final" submit

rheinertprheinertp Posts: 23Questions: 4Answers: 0

Hi,

I have a table (step) that contains several "modules" (one for source, one for destination).
The user can select those modules for each step - but he just has a maximum number of module-types.
I want to perform a check (on initSubmit ?) that he did not change/add a module that exceeds the maximum number for that module-type.

Is there a way to get these information from the database on an (presubmit) event and - in case of exceeding the number - roll-back
to the original values before the change (which I could save in a local) - or just refuse the creation of this new step?

Thanks a lot for some hints,
Pascal

Replies

  • colincolin Posts: 15,238Questions: 1Answers: 2,599
    edited March 2019

    Hi @rheinertp ,

    That's possible - if you look at the final example on initSubmit, it's issuing an ajax call to validate a user - you could have code similar to that. The rollback wouldn't happen, the user would have to cancel the edit, but as you say, you could set the value back with set() to what it was when the form was opened (initEdit).

    Hope that helps,

    Cheers,

    Colin

  • rheinertprheinertp Posts: 23Questions: 4Answers: 0

    Hi colin,
    that seems to be the right starting point - BUT there seems to be something missing:
    The data-array is not given to the PHP-function ...

    Javascript:
    stepeditor.on("initSubmit", function(e,action) {
     return new Promise( function ( resolve ) {
     $.ajax( {
          url: "licencemodule_process",
          type: 'POST',
          data: function(d) {
              d.stepid = (rowDataSTEP == null ? null : rowDataSTEP.tbladib_step.stepid); 
              d.srcModuleid = (rowDataSTEP == null ? editor.field( 'tbladib_step.srcModuleid' ).val(): rowDataSTEP.tbladib_step.srcModuleid);
              d.wsModuleid = (rowDataSTEP == null ? editor.field( 'tbladib_step.wsModuleid' ).val() : rowDataSTEP.tbladib_step.wsModuleid);
              d.destModuleid = (rowDataSTEP == null ? editor.field( 'tbladib_step.destModuleid' ).val() : rowDataSTEP.tbladib_step.destModuleid);
              d.ppModuleid = (rowDataSTEP == null ? editor.field( 'tbladib_step.postprocModuleid' ).val() : rowDataSTEP.tbladib_step.postprocModuleid);
          },
         success: function ( json ) {
             console.log(json);
             resolve( json.allowed );
         }
     } );
    } );                
    });
    
    PHP-Controller 
    public function licencemodule_process()
    {   
         $this->model_adib_config->checkAvailableLicenceModule($_POST);
    }
    
    PHP-Model
    public function checkAvailableLicenceModule($post)
    {
        $stepi = $post['stepid']; 
        $srcModuleid=$post['srcModuleid']; 
        $wsModuleid=$post['wsModuleid']; $destModuleid=$post['destModuleid']; $ppModuleid=$post['ppModuleid']; 
    .....
        if ($erg_string!=="")
            echo '{ "data": [{ "result": "failed", "hint": "' . $erg_string . '"} ]}';
        else
            echo '{ "data": [{ "result": "success", "hint": ""} ]}';
    }
    

    Problem is that $stepi = $post['stepid'] is always empty ... the function does get any _POST parameter...

    What is wrong with it?
    Thanks,
    Pascal

  • rheinertprheinertp Posts: 23Questions: 4Answers: 0

    Sorry!!!

    I solved it - not using the data function (d) - but by setting the values like this:

    data: {
        stepid: (rowDataSTEP == null ? null : rowDataSTEP.tbladib_step.stepid),
        srcModuleid: stepeditor.field( 'tbladib_step.srcModuleid' ).val(),
        wsModuleid: (rowDataSTEP == null ? stepeditor.field( 'tbladib_step.wsModuleid' ).val() : rowDataSTEP.tbladib_step.wsModuleid),
        destModuleid: (rowDataSTEP == null ? stepeditor.field( 'tbladib_step.destModuleid' ).val() : rowDataSTEP.tbladib_step.destModuleid),
        ppModuleid: (rowDataSTEP == null ? stepeditor.field( 'tbladib_step.postprocModuleid' ).val() : rowDataSTEP.tbladib_step.postprocModuleid),
    },
    
This discussion has been closed.