Unable to upload file using Bootstrap 5/Fastapi - fastapi

I am trying to upload a file using bootstrap 5 and fastapi.
Here is my html upload file block
<div class="mt-lg-3 mb-3">
<label for="formFile" class="form-label">Upload template (formats: .j2 or .html only)</label>
<input class="form-control" type="file" accept=".j2,.html" id="formFile" name="formFile">
</div>
when I submit the form its sending the file as string
Error: {"detail":[{"loc":["body","formFile"],"msg":"Expected UploadFile, received: <class 'str'>","type":"value_error"}]}
if I use the api its working fine. Can someone help me?

Added enctype="multipart/form-data" to form element and it worked. thank you #Mat for the solution

Related

Contact Form 7: Mail-tag with a custom file upload button

I made a custom label element with a for attribute attached to a file input element, and put it in the Form tab :
<label for="file-upload" class="label-file-upload">Choose a file</label>
<input id="file-upload" type="file">
I can upload a file but I don't know which mail-tag I have to put in the Mail tab in order to send it. I tried this :
[file-upload]
But it of course doesn't work. I suppose I have to add a form-tag in my code but I don't know how..
Any ideas ?
I ve found a solution:
<label for="file-upload" class="label-file-upload">Choose a file</label>
[file file-upload class:file-upload id:file-upload limit:2mb filetypes:jpg|zip|rar|doc|pdf|xls|docx|xlsx]
Mail-tag:
[file-upload]

store data in drupal 8

I have created form using twig template, the form has first name,last name and email.I need to save those values to database.
how can I create new table and store data in it??
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name: <input type="text" name="FirstName"><br>
Last name: <input type="text" name="LastName"><br>
Email: <input type="text" name="email" value="Mouse"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Can anyone help on that please??
You should use drupal's form api to create the form. Your way is not really "drupalish" way. Then you can define custom content type, with all the fields you need and if form submission handler of your form you can create new nodes in that type with data your form collected.
So google a bit, check some tutorial on form api, and how to make custome form and also on custom content types in drupal. Not that scare as it maybe looks to you right now.
Or, check on webform module that comes with D8 default installation, maybe you can use it instead!

How to add my CSS class to form in drupal 7

I newbie in drupal 7. I am writing new theme and I don't know how to add my class to form in drupal 7. I install ubercart to setup e-commerce website. I added new attribute for product (Size). I want to redesign in product page. In this page, It has size field but I don't know how to add my CSS. E.g:
<form action="/drupal-7.34/node/6" method="post" id="uc-product-add-to-cart-form-6" accept-charset="UTF-8"><div><div id="uc_product_add_to_cart_form-6-attributes" class="attributes"><div class="attribute attribute-1 odd"><div class="form-item form-type-select form-item-attributes-1">
<label for="edit-attributes-1">Size <span class="form-required" title="This field is required.">*</span></label>
<select id="edit-attributes-1" name="attributes[1]" class="form-select required"><option value="" selected="selected">- Select -</option><option value="1">39</option><option value="2">40</option><option value="3">41</option></select>
</div>
</div></div><input type="hidden" name="qty" value="1">
<input type="hidden" name="form_build_id" value="form-w06CKx7aNBiYShqfg8LiP98CaFLpEb8mgWzFYQWqnQ4">
<input type="hidden" name="form_token" value="JtZIrcKeIfXiVpwX43K6KqHPlZazR1klS1ht3W7PI9I">
<input type="hidden" name="form_id" value="uc_product_add_to_cart_form_6">
<div class="form-actions form-wrapper" id="edit-actions"><input class="node-add-to-cart form-submit" type="submit" id="edit-submit-6" name="op" value="Add to cart"></div></div></form>
I want to add my class to the select element. How can I do that?
In your theme directory there is file named theme_name.info . Inside of it there should be (or you can create it) array that defines css file which will be included on page. Check out explanation here:
https://www.drupal.org/node/171205
https://www.drupal.org/node/171209
So, you basically have to add path of your css file to that list and it will be included on every site page. Your html.php template must print out stylesheets variable (which will contain paths to css files). If you are not sure how to do it check how it's done on some standard drupal theme that comes with drupal installation.
After adding your css to theme info file don't forget to clear the cache!
Other way would be to include it manually, from page.tpl.php file. Just add there common CSS include line, like you would that in plain HTML file.
You can add CSS even from code with drupal_add_css() function, but that's a bit more advanced.
And you can use form id attribute to "aim" it and all inner elements with css.

Why my input with ng-model doesn't bind data to other element?

I have ASP.NET MVC5 application.
I included script like this:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
And I also did:
<input ng-model="someTest" type="text" />
<h1>Hello {{someTest}}</h1>
But when I write something into input, my <h1> doesnt update!
Console is clear, no errors, script is loaded correctly.
All I see on website is EXACTLY:
Hello {{someTest}}
What is wrong?
Even when I download script and include directly to project, problem is the same.
You likely need the ng-app tag, unless you have it somewhere that you aren't showing:
<div ng-app>
<input ng-model="someTest" type="text" />
<h1>Hello {{someTest}}</h1>
</div>

File upload using HTML file type

I want to upload a file on my aspx page.
I am using
<form id="frmId" method="post" enctype="Multipart/form-data">
<input type="file" id="file1"/>
<input type="submit" id="btnsubmit"/>
</form>
and in code behind I am trying to get this file. Its not letting me to get the file until I use server side input file control. I don't want to use runat="server" attribute with my file control.
Do anyone know how to do this.
Have you tried the Request.Files collection?
You can not access control on server side code with out runat="server" attribute.

Resources