我試圖避免離線的人在已註冊爲客戶的firecheckout頁面上輸入電子郵件。因此,我在我的一個開發控制器中創建了這個示例php腳本:Magento用jQuery通過電子郵件檢查客戶是否已經存在
public function mailExists(Varien_Object $customer, $mail, $websiteId)
{
if($websiteId){
$customer->setWebsiteId($websiteId);
}
$customer->loadByEmail($mail);
if($customer->getId()){
return $customer->getId();
}
return FALSE;
}
public function formAction()
{
$customer = Mage::getModel('customer/customer');
$websiteId = Mage::app()->getWebsite()->getId();
$email = $_POST['email'];
if($this->mailExists($customer, $email, $websiteId))
{
echo 'mail <u>'.$email.'</u> exists containing customer id '.$this->mailExists($customer, $email, $websiteId);
}
else{
$this->_formPost();
}
}
public function _formPost()
{
echo "<form enctype='multipart/form-data' action='".Mage::getUrl('index/form/')."' method='post'>";
echo "<input type='text' value='[email protected]' id='email' name='email' />";
echo "<input type='submit' value='verzend' />";
echo "</form>";
}
它工作得很好。但我擔心的是,當某人在結賬頁面輸入所有字段並按下提交按鈕時,所有輸入的數據都將被設置爲空。這會給我的客戶帶來挫敗感。所以我認爲jQuery腳本會更好地通知離線客戶不要使用已經註冊的電子郵件,或者當他們在電子郵件地址輸入字段中輸入電子郵件地址時登錄他們的賬戶。
我想讓我的jQuery腳本運行在用戶輸入的文本上的電子郵件輸入字段。 我只是想出了這一點:
public function testAction()
{
echo("
<script src='http://code.jquery.com/jquery-latest.js'></script>
<script type='text/javascript'>
$(document).ready(function()
{
$('#email').onChange(function()
{
alert('input');
});
});
</script>
");
$this->_testPost();
}
public function _testPost()
{
echo "<form name='test' enctype='multipart/form-data' action='".Mage::getUrl('index/form/')."' method='post'>";
echo "<input type='text' value='' id='email' name='email' />";
echo "<input type='submit' value='verzend' />";
echo "</form>";
}
這將打印input
的警告框。我將如何在jQuery中實現我的php檢查? 由於提前, 巴蒂爾
謝謝你回答我的問題!儘管如此,我發現了一個不同的解決方案。類似於@ @ input所寫的內容。 –