Skip to Content
Menu
This question has been flagged
1 Reply
2573 Views

How to create a web form with validation (example, email must have @ symbol, phone must have numbers and +-() symbols) without model?

Avatar
Discard
Best Answer

Hello Volodymyr,

For creating a website form, please refer to the below link:
https://www.cybrosys.com/blog/how-to-create-a-website-form-in-odoo-15

For creating form validations for different fields in the form web,

1) You can use field attributes like type="email" for email and type="tel" for phone etc. in input fields when creating a template of a particular form for the web.

2) For an email field you can do as follows: 


You can also specify pattern attributes inside the input field like pattern=".+@globex\.com" size="30".
This will automatically show validation like using "@" in email, etc. when the user enters the email and submits the form.

3) For a phone validation You can use input type="tel" and define your pattern for accepting phone numbers. 
 
You can customize your own pattern as needed.

Hope it will be helpful to you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Please find the Code for point 2 & 3
2 :
<input type="email" class="form-control" name="email" placeholder="Enter email"/>

3:
<input type="tel" id="phone" name="phone" pattern="['+']{1}[7-9]{1}[0-9]{9}" title="Phone number starting with +,following 7,8 or 9 as next digit and remaining 9 digits between 0-9"/>