How to insert form data into doctype using frappe builder

I’m using frappe builder for my website designing I want to insert form data into doctype ?how?

1 Like

I have the same doubt.
Have you already solved it?

Hi @Kaushik_Bansode @bdalmonico:

  1. Create textbox and button elements on Builder page. Use HTML attributes to provide id to each one. (mytextbox and mybutton)

image

image

  1. Create a server script (API) on Desk. Method name new-todo
request_args = frappe.form_dict
doc = frappe.new_doc("ToDo")
doc.description = request_args.get("description")
doc.insert()
frappe.response["message"] = doc
  1. On Builder page create a client script with this:
document.getElementById('mybutton').addEventListener('click', function() {
    const textboxValue = document.getElementById('mytext').value;
    console.log(textboxValue);
    
    fetch('/api/method/new-todo', {
            method: 'POST',
            headers: {'Content-Type':'application/json',"X-Frappe-CSRF-Token": frappe.csrf_token},
            body: JSON.stringify({
                description: textboxValue
            })
    })
    .then(response => response.json())
    .then(data => alert("Creado!"))
    .catch(error => console.error('Error:', error));
});

And …

Hope this helps!

1 Like