M
M
masimka2017-08-15 15:00:41
Kohana
masimka, 2017-08-15 15:00:41

What is the best way to implement the mechanism for saving data from a large form?

When editing a large form, the user sends a POST to the server. If the form is filled out incorrectly, I make a redirect indicating a filling error, while the data may be resent.
But after redirecting the form, the data is lost. How to make the user's form data remain after filling in and return filling errors to him?
Throw it all into local storage? or fill out the form according to the data previously filled in by the user?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Exploding, 2017-08-15
@Exploding

2017 is in the yard! Use ajax!

R
Roman Kalinger, 2017-08-15
@kalinger_roman

$(document).ready(function(){
      $("идентефикатор_кнопки_для_отправки_данных_формы").click(function() {
        //собераем все данные из формы
         var form_data = new FormData("идентификатор_формы");
            $.ajax({
            type: "POST", //Метод отправки
            url: "путь_до_файла",
            data: form_data,
            success: function() {
                        
            },
            error:function(){

            },
        });
    });
   });

Sending form data with ajax. On the server, we check the validity of the data and return the response. Depending on the answer, we either display an error or reset the form fields, depending on what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question