How to get webpage to send info in json format to doctype like web form

how to get webpage to send info in json format to doctype. I want it to be something of how the web forms do it except I want it to be on a web page

Create a web page under app/www.



Create the web page from website module.

Add below code in main section of your webpage.

<form class="form-inline">
<!--First Name-->
<div class="form-group">
<label class="sr-only" for="firstName">First Name</label>
<input type="text" class="form-control" id="firstName" placeholder="First Name" required>
<!--Last Name-->
<div class="form-group">
<label class="sr-only" for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" placeholder="Last Name" required>
<!--Submit Button-->
<button type="submit" class="btn btn-default">Submit</button>

Add below code in script:

$(document).ready(function() {
     $('form').on('submit', function(event) {{
			method: "yourcustomapp.api.get_from_data", // write a function in api file
				'fname': $('#firstName').val(),
				'lname': $('#lastName').val(),
			callback: function(r) {
				frappe.msgprint("Your Message")

In file,

from __future__ import unicode_literals
import frappe

def get_from_data(fname,lname,gnore_permissions=True):
	data = frappe.new_doc("Lead")
	data.lead_name = fname + lname

Above code will create the new Lead in database.

1 Like