Jump to content

submit form with json in Bootstrap


raduenea

Recommended Posts

In Bootstrap I have the following piece of code that validate all the fields in the form:

        /**
         * Called when all validations are completed
         */
        _submit: function() {
            var isValid   = this.isValid(),
                eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
                e         = $.Event(eventType);

            this.$form.trigger(e);

            // Call default handler
            // Check if whether the submit button is clicked
            if (this.$submitButton) {
                isValid ? this._onSuccess(e) : this._onError(e) ;
										

            }
        },

What I want is if it's success (this._onSuccess(e)) to submit the form with the following code json:


$("document").ready(function(){
							 
  $(".js-ajax-php-json").submit(function(){
										   
    var data = {
      "action": "test"
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "https://www.telekom.ro/delivery/formAction/fix-mobil/response.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
		  
        $(".the-return").html(
          //"Favorite beverage: " + data["favorite_beverage"] + "<br />Favorite restaurant: " + data["favorite_restaurant"] + "<br />Gender: " + data["gender"] + "<br />JSON: " + data["json"]
		  data["ok"]
        );
 
         $(".error").html(
		  data["error"]
        );

 
        //alert("Form submitted successfully.\nReturned json: " + data["json"]);
      },
	   
	  
	  
    });
    return false;
  });
});

I tried to replace the "e" from (this._onSuccess(e)) with the code from above but not success. Both code works good individual.

Practicaly I need to submit the form, then all the fields are validated, with that json code.

 

Can anyone help me please?

 

 

Link to comment
https://forums.phpfreaks.com/topic/292406-submit-form-with-json-in-bootstrap/
Share on other sites

In Bootstrap I have the following piece of code that validate all the fields in the form:

        /**
         * Called when all validations are completed
         */
        _submit: function() {
            var isValid   = this.isValid(),
                eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
                e         = $.Event(eventType);

            this.$form.trigger(e);

            // Call default handler
            // Check if whether the submit button is clicked
            if (this.$submitButton) {
                isValid ? this._onSuccess(e) : this._onError(e) ;
										

            }
        },

What I want is if it's success (this._onSuccess(e)) to submit the form with the following code json:


$("document").ready(function(){
							 
  $(".js-ajax-php-json").submit(function(){
										   
    var data = {
      "action": "test"
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "https://www.telekom.ro/delivery/formAction/fix-mobil/response.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
		  
        $(".the-return").html(
          //"Favorite beverage: " + data["favorite_beverage"] + "<br />Favorite restaurant: " + data["favorite_restaurant"] + "<br />Gender: " + data["gender"] + "<br />JSON: " + data["json"]
		  data["ok"]
        );
 
         $(".error").html(
		  data["error"]
        );

 
        //alert("Form submitted successfully.\nReturned json: " + data["json"]);
      },
	   
	  
	  
    });
    return false;
  });
});

I tried to replace the "e" from (this._onSuccess(e)) with the code from above but not success. Both code works good individual.

Practicaly I need to submit the form, then all the fields are validated, with that json code.

 

Can anyone help me please?

This is JS not PHP

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.