我正在尝试this tutorial。我创建了一个index.php,其中包含一个包含以下代码的表单。问题是表单根本没有提交。警报没有被调用。什么都没发生。
<?php
require_once ('/soapclient/inc_connection.php');
function insert()
// if(isset($_POST['submit']))
{
//Describing the Leads object and printing the array
$describe = $connection->describeSObjects(array('Lead'));
print_r($describe);
//Create New Lead
$leadFirstName = "Ahmed";
$leadLastName = "Dirie";
$leadCompany = "Pick Yours Up";
$leadEmail = "adirie@pickyoursup.com";
//Creating the Lead Object
$lead = new stdClass;
$lead->type = 'Lead';
$lead->fields = array(
'FirstName' => $leadFirstName,
'LastName' => $leadLastName,
'Company' => $leadCompany,
'Email' => $leadEmail
);
//Submitting the Lead to Salesforce
$result = $connection->create(array($lead), 'Lead');
}
?>
HTML:
<h3>Sign up for an evaluation:</h3>
<span id="php_code"> </span>
<form action="https://docs.google.com/..../formResponse" method="POST" id="" target="_self" ><ol style="padding-left: 0">
<div class="ss-form-question errorbox-good">
<input type="button" name="submit" value="Contact Us" id="ss" onclick="return postToSql();"/>
....
JS:
<script type="text/javascript" src="libs/jquery-1.7.1.js" ></script>
<script type="text/javascript">
function postToSql()
{
alert('1');
alert("<?php insert(); ?>");
//return false;
}
</script>
答案 0 :(得分:0)
可能是PHP函数“insert()”的输出值导致javascript错误。所以你的javascript函数似乎未定义。尝试将insert()函数更改为此,您将看到差异。
function insert()
{
echo "something to alert";
}
然后,
function insert()
{
echo 'something " to alert';
}
要解决此问题,请确保您的函数的输出值不会因为Quotation(“)和Apostrophe(')Marks而导致错误。
如果你需要像这样使用Javascript和PHP,我建议使用Ajax。