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:
- Create textbox and button elements on Builder page. Use HTML attributes to provide id to each one. (
mytextbox
andmybutton
)
- 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
- 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!
3 Likes