简体   繁体   中英

Magento 1.4 $_POST['field_name'] not working

I am trying to make a custom field in the onepage checkout process. I have the following code in the checkout.phtml:-

<input name="field_name" type="text"></input>
$postData = Mage::app()->getRequest()->getPost();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(isset($postData['field_name'])){
    $fn = $postData['field_name'];
}else{
    $fn = '';
}   
$sql_ac = "INSERT INTO `account` (`sn`,`order_id`,`acc_no`) VALUES (NULL,'".$orderId."','".$fn."')";
$acc_no = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $acc_no->query($sql_ac);

However, when I check phpmyadmin, there is an entry in the sn and order_id column but the acc_no column is blank even when I entered something in the input field "field_name". I tried to echo the variable $fn but it shows empty. How can I get an input field value? I tried the usual $_POST method but is still the same.

try using

$field_name = Mage::app()->getRequest()->getPost('field_name');
echo $field_name;

let me know if it works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM