0

このチュートリアルを試しています。次のコードを含むフォームを含む 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>
4

1 に答える 1

0

おそらく、PHP 関数「insert()」からの出力値が JavaScript エラーを引き起こしている可能性があります。したがって、JavaScript関数は未定義のようです。insert() 関数をこれに変更してみてください。違いがわかります。

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

その後、

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

この問題を解決するには、Quotation(") および Apostrophe(') マークが原因で、関数の出力値がエラーを引き起こさないようにしてください。

このように Javascript と PHP を組み合わせて使用​​する必要がある場合は、Ajax を使用することをお勧めします。

于 2013-10-22T11:12:09.940 に答える