14

I'm using WordPress Ninja Forms and I'm trying to create a form preview which has to be accepted before the Data is sent via Ajax. That means I need to add custom JS-Code between the form validation and the submit process.

So far I tried the following:

var form_id = 1;
var PreviewFormController = Marionette.Object.extend({

  initialize: function() {
    Backbone.Radio.channel( 'form-' + form_id ).reply( 'maybe:submit', this.PreviewForm, this, form_id);
  },

  PreviewForm: function(formID){

    var formModel = nfRadio.channel( 'app' ).request( 'get:form', formID );

    if(formModel.getExtra('previewOk')){
      return true;
    }
    this.ShowPreview( formModel );
    return false;
  },

  ShowPreview: function(formModel){
    if(confirm("You sure?")){
      nfRadio.channel( 'form-' + form_id).request( 'add:extra', 'previewOk', true );
      nfRadio.channel( 'form-' + formModel.get( 'id' ) ).request( 'submit', formModel );
    }
  }
});

$(function(){
    new PreviewFormController();
});

The problem is that PreviewForm now comes before the field validation. How is it possible to hook the function after the field validation?

I'm a bit lost since the Codex does not seem to be ready yet. I'd be so glad if someone could help me there..

Nico Martin
  • 1,268
  • 1
  • 14
  • 23

1 Answers1

0

I believe you want to use this

initialize: function() {
    this.listenTo( Backbone.Radio.channel( 'forms' ), 'init:model', this.PreviewForm );
},
Tim Hallman
  • 854
  • 15
  • 27