So what I am trying to do is get some data from user in a form and as user presses submit button, the data should be added in the Lead’s module database. But the issue which is coming is that the controller file(controller.php) is not being executed. even though the control reaches to the ajax success function.
Following is the index.html code:
<!DOCTYPE html>
<html>
<head>
<title>Submit Form Using AJAX and jQuery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="./script.js"></script>
</head>
<body>
<h2>Submit Form Using AJAX and jQuery</h2> <!-- Required div Starts Here -->
<form action="index.php?module=Leads&action=action_insert" method="POST">
<div id="form">
<h3>Fill Your Information !</h3>
<div>
<label>Name :</label>
<input id="name1" type="text">
<label>Email :</label>
<input id="email" type="text">
<label>Password :</label>
<input id="password" type="password">
<label>Contact No :</label>
<input id="contact" type="text">
<input id="submit" type="button" value="Submit">
</div>
</div>
</div>
</body>
</html>
Following is the controller.php code :
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CustomLeadController extends SugarController
{
public function action_insert()
{
$GLOBALS['log']->fatal("I am in controller");
return true;
}
}
Following is script.js code:
$(document).ready(function () {
$("#submit").click(function ()
{
var name = $("#name1").val();
var email = $("#email").val();
var password = $("#password").val();
var contact = $("#contact").val();
// Returns successful data submission message when the entered information is stored in database.
var data ='&name2=' + name1;
data += '&email1=' + email ;
data += '&password1=' + password;
data += '&contact1=' + contact
console.log(data); //data is printed successfully
$.ajax({
// type: "POST",
url: "controller.php",
data: data,
success: function () {
console.log('error2'); // error 2 gets printed successfully
}
, error: function () {
console.log('error');
}
});
});
});