0

I have the following form created in my HTML, this will be submitted to "url 'submitrecord'". This will work fine for single entry per HTML. How can I add multiple entries of this type and submit at once.

Code:

<form method='POST' action="{% url 'submitrecord' %}">
      <div class="row">
             <div class = "col-md-1 form-group">
                    <input type="text" class="form-control" name="EntryNo"  placeholder="EntryNo"/>
            </div>
            <div class = "col-md-2 form-group">
                    <input type="text" class="form-control" name="MedicineName" placeholder="MedicineName"/>
            </div>
                    <button type="submit" class="btn btn-default">Done</button>
    </div>       
</form>
10
  • Look into django formsets Commented Jul 3, 2016 at 17:34
  • Could you handle it server side? Commented Jul 3, 2016 at 17:35
  • Im not sure how can i use formsets here? Commented Jul 3, 2016 at 17:36
  • 1
    I'd probably use AJAX to POST one form, and onSuccess post the next. If you have to do it on one server roundtrip, then I'd use jquery .serialize() or json_encode each form and then send as an array to be decoded server-side Commented Jul 3, 2016 at 17:47
  • HI @json im new to web development, an example will give me more insight. Commented Jul 3, 2016 at 17:58

1 Answer 1

0

I found this answer but still it isnot sending the request to my URL.

<script>
$(document).ready(function(){
 var called = 0;
ajax_recaller = function(forms){
$.ajax({
type: "POST",
data: forms[called].serialize(),                             
url: forms[called].attr('action'),                        
success: function(data) {
called++;                                                                        
 if(called < forms.length) {
ajax_recaller(forms);                                        
} else {
called=0;                                                                    // set called value to 0 again
alert('All forms has been submitted!');
}

}
});

}


$(document).on('click','.submitforms',function(){
var x=0;

$('.ajax_form').each(function(){
forms[x] = $(this);
x++;
});

ajax_recaller(forms);
});

});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.