This question has been flagged
3 Replies
3882 Views

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?

Avatar
Discard
Author

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

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)


Avatar
Discard