Dear all
I have been trying to work with custom forms as my form tries to feed in
data into a table that references some data from another table. Also, I
would like to upload a variable number of files to the database through the
same form. But the uploaded/selected file is not being referenced as a
storage object but rather a string object. Request you all to please help
me with this, I have been stuck on this for days now :(
View File: index.html
{{extend 'layout.html'}}
<!-- For adding a name to the uploaded file visit --
https://stackoverflow.com/questions/8008213/web2py-upload-with-original-filename
-->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$fileNumber = 1
$(document).ready(function(){
$("#btn1").click(function(){
$("#attachments").append("<tr>"+
"<td><div
id='attachment"+$fileNumber+"'>Attachment "+$fileNumber+"</div></td>"+
"<td style='width:80%' ><div
id='attachment_input"+$fileNumber+"'><input class = 'upload' type='file'
required name='file"+$fileNumber+"'></div></td>"+
"</tr>"+
"</div>");
document.getElementById('number_of_attachment').value = $fileNumber;
$fileNumber += 1;
});
$("#btn2").click(function(){
if($fileNumber > 1) {
$fileNumber -= 1;
$("#attachment"+$fileNumber).remove();
$("#attachment_input"+$fileNumber).remove();
document.getElementById('number_of_attachment').value =
$fileNumber-1;
}
});
});
</script>
<form action="{{=URL('saveEmail')}}" method="post" id="email">
<table style="width:100%">
<tr>
<td>Project Name</td>
<td>
<select form="email" name="projectName" required>
{{for key, value in projects.items() :}}
<option value="{{=value}}">{{=key}}</option>
{{pass}}
</select>
<a href="{{=URL('addProject')}}">If Project not visible
here then add new project here</a>
</td>
</tr>
<tr>
<td>Item Type</td>
<td>
<select form="email" name="itemSelected" required>
{{for key, value in material.items() :}}
<option value="{{=value}}">{{=key}}</option>
{{pass}}
</select>
<a href="{{=URL('addItem')}}">If item not visible here then
add new item here</a>
</td>
</tr>
<tr>
<td>Subject:</td>
<td style="width:80%" ><input type="text" name="subject"
required></td>
</tr>
<tr>
<td>Body:</td>
<td style="width:80%" ><textarea name="body"
required></textarea></td>
</tr>
</table>
<table id = "attachments" style="width:100%">
</table>
<table >
<tr>
<td><button type='button' id="btn1">Attach File</button></td>
<td><button type='button' id="btn2" >Remove File</button></td>
</tr>
<tr>
<input id='number_of_attachment' type='hidden' name='attachments'
value=0>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
Thanks!
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{{extend 'layout.html'}}