ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

REST Api from custom HTML form


I created a custom html form with a custom method inside .py file and a custom js file for the html page
and i used REST api to create a new document in my custom doctype which is inside a custom module
i get some errors

my custom module name: Customer Forms
My custom doctype: Contact Us Form
the full_name and email_address fields are only the required fields all of the others are optional and i use series as the Auto Naming “New Message - #####”

here are my codes:


    <div class="form-group">
        <label>Email address</label>
        <input type="email" class="form-control" name="email">
    <div class="form-group">
        <label>Full Name</label>
        <input name="fullname" class="form-control" type="text">
    <button class="btn btn-primary btn-send">Submit</button>


frappe.ready(function() {

        $('.btn-send').off("click").on("click", function() {
                var email = $('[name="email"]').val();
                var name = $('[name="fullname"]').val();
                    method: "erpnext.customer_forms.doctype.contact_us_form.testform.send_contactusform",
                    args: {"full_name": name, "email_address": email},
                    callback: function(r) {
                        if(r.message==="okay") {
                                                            frappe.msgprint("{{ _("Thank you for your message") }}");
                        } else {
                                                            frappe.msgprint("{{ _("There were errors") }}");

from __future__ import unicode_literals

import frappe
from frappe.utils import now
from frappe import _

def send_contactusform(full_name, email_address):
    newmsg= frappe.get_doc({
                        "doctype": "Contact Us Form",
                        "full_name": full_name,
                        "email_address": email_address
    return "okay"

the errors i get are:

jquery.min.js:4 POST 500 (INTERNAL SERVER ERROR)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
call @ website.js:64
(anonymous) @ testform:254
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3


website.js:162 Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 56, in execute_cmd
    return, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 1019, in call
    return fn(*args, **newargs)
TypeError: send_contactusform() takes exactly 1 argument (0 given)

and i put these as the inputs of the fields (test,

i donno what is the problem exaclty but if anyone could help me it would be great

and here is my url of the custom form


try with default values for params in the py

def send_contactusform(full_name="", email_address=""):

if the error still persists then probably your function path is wrong.