Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to add country, state and file attachment in my website form in odoo13, not by drag & drop?

Subscribe

Get notified when there's activity on this post

This question has been flagged
Odoo13.0Odoo13odoo13odoo13CE
3 Replies
6047 Views
Avatar
Aishwarya

This is how my form looks

<? xml version = "1.0" encoding = "UTF-8"?>

<odoo>

    <template id = "tmp_customer_form" name = "Partner Form">

        <t t-call = "website.layout">

            <div id = "wrap" class = "alumni">

                <div class = "container">

                    <div class = "col-md-12">

                        <form action = "/ customer / form / submit">

                            <table border = "0" width = "100%" class = "table-sign">

                        <tbody>

                            <tr>

                                <th colspan = "3" style = "color: #ffffff;"> Identify Yourself </th>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "name"> Alumni Name (Full) </label>

                                </ Td>

                                <td width = "2%" align = "center">

                                    <B>: </ b>

                                </ td>

                                <td width = "77%">

                                    <input type = "text" name = "name" id = "name" size = "40" required = "" />

                                </ td>

                            </ tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "date"> Date Of Birth [DD / MM / YY] </label>

                                </ td>

                                <td width = "2%" align = "center" valign = "top">

                                    <B>: </ b>

                                </ Td>

                                <td width = "77%" valign = "top">

                                    <input type = "date" name = "date" size = "10" maxlength = "10" required = "" />

                                </ td>

                            </ Tr>

                           

<Tr>

                                <td width = "21%"> </td>

                                <td width = "2%" align = "center">

                                    <B>: </ b>

                                </ Td>

                                <td width = "77%">

                                    <input type = "text" name = "my_teachers1" id = "my_teachers1" size = "20" />

                                </ td>

                            </ tr>

                            <tr>

                                <th colspan = "3" style = "color: #ffffff;"> Contact Details </th>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "city"> City </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </ td>

                                <td width = "77%">

                                    <input type = "text" name = "city" id = "city" size = "30" required = "" />

                                </ td>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "state_id"> State </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </ td>

                                <td width = "77%">

                                    <input type = "text" name = "state_id" id = "state_id" size = "30" required = "" />

                                </td>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "country_id"> Country </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </td>

                                <td width = "77%">

                                    <input type = "text" name = "country_id" id = "country_id" size = "30" required = "" />

                                </td>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "phone"> Mobile No. </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </td>

                                <td width = "77%">

                                    <input type = "text" name = "phone" id = "phone" />

                                </td>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "email"> Email </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </td>

                                <td width = "77%">

                                    <input type = "email" name = "email" id = "email" size = "30" />

                                </td>

                               <td width = "2%" align = "center">

                                    <b>: </ b>

                                </td>

                                <td width = "77%">

                                    <textarea name = "about" id = "about" rows = "5" cols = "50"> </textarea>

                                </td>

                            </tr>

                            <tr>

                                <td width = "21%">

                                    <label for = "image_1920"> Upload Photo </label>

                                </td>

                                <td width = "2%" align = "center">

                                    <b>: </ b>

                                </td>

                                <td width = "77%">

                                    <input type = "file" name = "image_1920" id = "image_1920" />

                                </td>

                            </tr>

                            <tr>

                                <td width = "21%"> </td>

                                <td width = "2%" align = "center">

                                    <b> </ b>

                                </td>

                                <td width = "77%">

                                    <input type = "submit" value = "Submit"> </input>

                                </dd>

                            </tr>

                        </tbody>

                    </table>

                 </ form>

                </div>

              </div>

          </t>

    </template>


    <template id = "tmp_customer_form_success" name = "Customer Form Successfully Submitted">

        <t t-call = "website.layout">

            <div id = "wrap">

                <div class = "container">

                    <div class = "col-md-12">

                        <div class = "alert alert-success">

                            <p> Thank You! </ P>

                            <p> Your form has registered successfully </p>

                        </div>

                    </ div>

                </div>

            </ div>

        </ t>

    </ template>

</ odoo>

Here is my controller.py

from odoo import http

from odoo.http import request

class AlumniForm (http.Controller):

    #mention class name

    @ http.route (['/ customer / form'], type = 'http', auth = "public", website = True)

    #mention a url for redirection.

    #define the type of controller which in this case is 'http'.

    #mention the authentication to be either public or user.

    def alumni_form (self, ** post):

    #create method

    #this will load the form webpage

        return request.render ("sample.tmp_customer_form", {})

    @ http.route (['/ customer / form / submit'], type = 'http', auth = "public", website = True)

    #next controller with url for submitting data from the form #

    def alumni_form_submit (self, ** post):

        partner = request.env ['res.partner']. create ({

            'name': post.get ('name'),

            'date': post.get ('date'),

            'city': post.get ('city'),

            'state_id': post.get ('state_id'),

            'country_id': post.get ('country_id'),

            'phone': post.get ('phone'),

            'email': post.get ('email'),

            'image_1920': post.get ('image_1920'),

        })

        vals = {

            'partner': partner,

        }

        #inherited the model to pass the values ​​to the model from the form #

        return request.render ("sample.tmp_customer_form_success", vals)

Now, the coutry, state & the attachment file are not linking to the backend, what should I do?

0
Avatar
Discard
Sehrish

File Attachment or Upload: http://learnopenerp.blogspot.com/2019/01/add-attachement-file-from-odoo-website.html

Aishwarya
Author

Have you worked in that? It's not working for me

Avatar
Mustufa Rangwala
Best Answer

Hello,

You can try:

=======

<div t-attf-class="col-lg-6 o_website_form_custom_attchments">

                                            <label class="control-label" for="Attachments" >Attach Files</label>

                                            <input type="file" class="form-control o_website_form_input" name="attachment" multiple='multiple'/>

                                            <div>

                                                <label style="color:grey; font-size:12px;" >Multiple files Attachments</label>

                                            </div>

                                        </div>

=======

in controller you can write:

attachment_list = request.httprequest.files.getlist('attachment')

            for image in attachment_list:

                if post.get('attachment'):

                    attachments = {

                               'res_name': image.filename,

                               'res_model': 'machine.repair.support',

                               'res_id': support,

                               'datas': base64.encodestring(image.read()),

                               'type': 'binary',

                               # 'datas_fname': image.filename, odoo13

                               'name': image.filename,

                           }

                    attachment_obj = http.request.env['ir.attachment']

                    attach = attachment_obj.sudo().create(attachments)

====

Regards,

Mustufa Rangwala (Probuse)


0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to put domain filter on One2Many Field on a from Solved
Odoo13.0 Odoo13 odoo13 odoo13CE
Avatar
1
Nov 21
4576
Having trouble installing the website module in a fresh DB
Odoo13.0 odoo13.0 Odoo13 odoo13 odoo13CE
Avatar
0
Nov 21
3294
Database problem
Odoo13.0 odoo13.0 Odoo13 odoo13 odoo13CE
Avatar
Avatar
Avatar
Avatar
8
Mar 20
10423
Error with search content in elearning platform of Odoo 13
Odoo13.0 odoo13.0 Odoo13 odoo13 odoo13CE
Avatar
0
Oct 19
3897
Error with newsletter block of website builder in ODOO 13
Odoo13.0 odoo13.0 Odoo13 odoo13 odoo13CE
Avatar
0
Oct 19
4625
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now