2013-10-22 74 views
0

我正在尝试this tutorial。我创建了一个包含下面代码的表单的index.php。问题是表单根本没有提交。警报没有被调用。什么也没发生javascript函数onsubmit无法正常工作

<?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 = "[email protected]"; 

//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

你想做什么...? – Dinesh

+0

试图发布数据到salesforce onsubmit。墨水贴)。 – adityawho

+1

检查控制台..获取任何错误? –

回答

0

可能,从你的PHP函数的输出值 “插入()” 导致JavaScript错误。所以你的JavaScript函数似乎是未定义的。尝试改变你的insert()函数,你会看到不同之处。

function insert() 
{ 
    echo "something to alert"; 
} 

然后,

function insert() 
{ 
    echo 'something " to alert'; 
} 

为了解决这个问题,请确保您的函数的输出值不会导致因为报价(“)和撇号的错误(')标记。

如果您需要使用Javascript和PHP这样的组合,我建议使用Ajax。

+0

好吧,你是rt。但是我的php函数的输出怎么会影响它。我只是试图将数据发送给salesforce。你建议我应该怎么做?除了ajax,我的意思是...... – adityawho

+0

在代码中有'print_r($ describe);'这个输出可能会导致错误。尝试删除它。 – CeritT

+0

不,不是。它的第一行和最后一行在我的PHP – adityawho