2015-11-17 175 views
2

我已經從我發佈的問題重定向here 現在我有另一種形式在重定向頁面,我需要輸入名稱和手機號碼,如果它匹配我的數據庫表的HelloWorld將進入一個頁面或者另一個驗證自定義模塊在magento中的自定義表

<p>You have successfully registered</p> 
<div> 
    <label>Login</label> 
</div> 
<div> 
    <form action="" method="post"> 
     <label> Username </label> 
     <strong>:</strong> 
     <input class="input-text required-entry" type="text" name="fname" maxlength="20"> 
     <label>Mobile No</label> 
     <strong>:</strong> 
     <input class="required-entry" type="number" maxlength="10" name="mobileno"> 
     <input type="submit" name="login" value="Login">&nbsp;&nbsp;&nbsp;&nbsp; 
     <input type="button" name="cancel" value="Cancel"> 
    </form> 
</div> 

任何一個可以幫助我如何不,我可以在數據庫現有數據進行驗證,使這項工作?我應該使用索引控制器來啓動它還是有任何magento方式?

更新:

這是我Indexcontroler.php低於答案更新後

<?php 
class MyCustom_Helloworld_IndexController extends Mage_Core_Controller_Front_Action 
{ 

/* 
* this method privides default action. 
*/ 
public function indexAction() 
{ 
if($this->getRequest()->getParams()) { 
$param = $this->getRequest()->getParams(); 


echo $firstname = $param['fname']; 
$lastname = $param['lname']; 
$address = $param['address']; 
$state = $param['state']; 
$city = $param['city']; 
$mobile = $param['mobileno']; 



$model = Mage::getModel('helloworld/helloworld'); 
// $model->setTitle($title); 
$model->setFirstname($firstname); 
$model->setLastname($lastname); 
$model->setAddress($address); 
$model->setState($state); 
$model->setCity($city); 
$model->setMobileno($mobile); 
$model->save(); 
$this->_redirect('helloworld/index/login'); 
// $this->_redirectReferer(); 
}else { 


/* 
* Initialization of Mage_Core_Model_Layout model 
*/ 
$this->loadLayout(); 
/* 
* Building page according to layout confuration 
*/ 
$this->renderLayout(); 

} 



} 
public function loginAction() 
{ 
$this->loadLayout();  
$this->renderLayout(); 

} 
public function loginnAction() 
    { 
    if($this->getRequest()->getParams()) { 
    $param = $this->getRequest()->getParams(); 


     $username = $param['fname']; 
     $mobile = $param['mobileno']; 

     $check = Mage::getModel('helloworld/helloworld') 
       ->AddFieldToFilter('mobileno', array('eq' => $mobile)) 
       ->AddFieldToFilter('fname', array('eq' => $username)); 
if(count($check)==1) { 
$this->_redirectReferer(); 
}else { 
$this->_redirect('helloworld/index/login'); 
    } 

} 
} 
} 
+0

哪裏是用戶名字段不在的一部分上一個問題? –

+0

多數民衆贊成多數民族裔,我已標記爲用戶名這裏 – Melvin

+0

添加答案嘗試和反饋... –

回答

1

您可以添加檢查一樣,

public function loginAction() 
      { 
      if($this->getRequest()->getParams()) { 
      $param = $this->getRequest()->getParams(); 


       $username = $param['fname']; 
       $mobile = $param['mobile']; 

       $connectionresource = Mage::getSingleton('core/resource'); 
$readconnection = $connectionresource->getConnection('core_read'); 

$table = $connectionresource->getTableName('helloworld/helloworld'); 
$allrecord = $readconnection->select()->from(array('helloworld'=>$table))->where('helloworld.mobileno=?', $mobileno) 
->where('helloworld.fname=?', $username); 
$alldata =$readconnection->fetchAll($allrecord); 
    if(count($alldata)==1) { 
     $this->_redirect('home'); 
     }else { 
     $this->_redirect('customer/account'); 
      } 

     } 
+0

我已將public function loginAction()重命名爲public function loginnAction(),那會是一個問題嗎?它仍然加載相同的頁面 – Melvin

+0

不是沒有問題,它不會加載相同的頁面。你的表單行爲是什麼? –

+0

我還沒有給任何行動 – Melvin