javascript - How to make a hidden form with a file field -
i have dynamically generated table editable. on clicking cell in table can change text.
in 1 column there image displayed. when user clicks on change html column <input type='file'>
, trigger click hence making user choose file upload icon.
in last column of table have commit button. if user makes changes , presses commit have pick whole row ( text fields , 1 file field ) , add contents form including file user chose , send python script upload s3 server.
my question is: how send form?
i'm using script not working sending text request.files
turns out empty @ python(django) script side.
function update(a) { try { var button = $(a); var row = $(button.parent()); var rowcount = button.parent().parent().parent().children().index(button.parent().parent()); var filerow = ''; var formrow = new array(); var rowkey = new array('topic', 'topicdescription'); var cnt = 0; var form = $('#dyno_form'); row.siblings().each(function () { if ($(this).find($('input:file')).length > 0) { $(this).find($('input:file')).appendto($(form)); } else if ($(this).find($('img')).length == 0) { formrow[cnt++] = '<input type="text" value="' + $(this).html() + '" name="' + rowkey[cnt - 1] + '"/>'; } }); $(form).append(formrow[0]); $(form).append(formrow[1]); $(form).submit(); } catch (a) { alert(a); } }
and here html:
<form id='dyno_form' action='' method="post" style="visibility:hidden">{% csrf_token %}</form>
how go doing this?
when want upload file form
element needs have correct enctype
attribute , method must post
.
<form enctype="multipart/form-data" method="post" ...
otherwise values of inputs uploaded.
Comments
Post a Comment