Odoo Help

8

How to do Custom Forms in v8 website?

By
Frank Adler
on 9/13/14, 5:02 AM 18,350 views

How can I add custom frontend forms in v8?

See below for a step-by-step guide.

17
Frank Adler
On 9/13/14, 5:19 AM

Hi, 

After some experimenting I managed to set up custom forms through the front-end of Odoo in v8 website builder.

The short version: create a new page from website_builder and copy the HTML sources of contactus and contact_form together into your new page. Remove the kwargs div and start configuring to your liking.

...and these are the step-by-step instructions and some tips and tricks at the bottom:

  1. Create a new page from the frontend (Content - New Page)
  2. Open the 'Contact Us' form and go to Customize - HTML Editor
  3. Copy the <div id="wrap">....</div> and its entire content (i.e. the entire page minus the <t> tags)
  4. Go back to your 'new page', customize - HTML editor and delete everything between its <t> tags
  5. Paste your form code between the <t> tags instead.
  6. Go back to your 'Contact Us' form, customize - HTML editor.
  7. From the dropdown select the file ' - Contact Form' (it should now say "Template ID: website_crm.contactus_form" at the top)
  8. Copy the entire <form ....>...</form> tag incl its content
  9. Back to the 'new page', customize - HTML Editor
  10. Now replace the <div ... name="mail_button" > and its entire contenct with the <form> tag and its content by hitting paste (from point 8).
  11. Now comment out or delete the section (IMPORTANT)
    <t t-foreach="kwargs" t-as="kwarg">
         <input type="hidden" t-att-name="kwarg[0]" t-att-value="kwarg[1]"/>
    </t>
  12. This is essentially it. Now you have a functioning copy of the contact form and you can start to modify it as nicely demonstrated here  https://www.youtube.com/watch?v=lKnkyh0ctUI

Tips & Tricks:

You can use any of the field names in the Sales Lead Form to directly insert values into the desired fields from your form. For instance I wanted to make sure that each 'Lead' from this form is marked as coming through a separate channel. To do this I added a new Channel "Custom Form Submission" (which in my case got Channel ID in the db). Channels are e.g. accessible from the Sales Lead form under Extra Info - Marketing. Then by adding a hidden field to the form's form-group, each form submission creates a lead which will have the right channel associated with it.

The code for the hidden field is below. Make sure to adjust the t-attf-value (i.e. the channel id) according to your setup:

<div t-attf-class="form-group">
     <div class="col-md-7 col-sm-8">
         <input type="hidden" class="form-control" name="medium_id" t-attf-value="6"/>
     </div>
</div>

This should work with all your fields if you get the fieldname and the data type right.

Hope this helps everyone.

Regards
Frank

0
elenahelmeca
On 1/12/18, 9:41 AM

Hello! great post @Frank Adler , 

I am trying to do the same operation but using the recruitment module. I am trying to insert values into the applicant profile (equivalent to a Lead in your example) from the contact form which is filled by the candidate itself. I added a new field in the contact form (for example, the surname of the candidate) like follows:


<div class="form-group form-field o_website_form_required_custom">

    <div class="col-md-3 col-sm-4 text-right">

        <label class="control-label" for="x_surname">Your surname</label>

    </div>

    <div class="col-md-7 col-sm-8">

        <input type="text" class="form-control o_website_form_input" name="x_surname" required=""/>

    </div>

</div>


At the same time, I created the field x_surname on the Odoo backend as explained in the video. But when the applicant fills the form, every predefined field  (name, email, phone...) is well inserted but not the surname that I created.

Do you have any idea what can be missing?


Thank you so much!

-1
Alessandro D'Armiento
On 11/13/15, 11:12 AM

Hello! All works fine, do you know btw how to redirect the user in the same page instead the /crm/contactus after the message is sent?

-1
LIfe
On 9/20/14, 2:03 AM

hello Frank Adler

i am really happy with this tips

thank you very muchhhhhhhh

-1
Adam Moonen
On 6/2/15, 8:48 PM

That is awesome, thank you...

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

8 follower(s)

Stats

Asked: 9/13/14, 5:02 AM
Seen: 18350 times
Last updated: 1/12/18, 9:54 AM