0

我有Zend一个PHP表格:

<form action="https://example.com/checkout/" name="info" method="post"> 
    <div id="payment">
        <div id="paypal>
            <?php $this->is_paypal_payment = true; ?>
        </div>
        <div id="credit_card>
            <?php $this->is_paypal_payment = false; ?>
        </div>
    </div>
</form>

当用户点击提交按钮时,如何在Controller中设置实例变量?

这是我尝试过的,但没有奏效。

控制器:

$this->view->payment_option_paypal = false;  // initialized value

$payment_method_option = $this->_getParam('payment_option_paypal', null);
if (!is_null($payment_method_option)) {
   if ($payment_method_option == 'paypal') {
       $this->_is_paypal = true;
   }
}

看法:

<div id="paypal" style="display: none;">
    <?php $this->payment_option_paypal = "paypal"; ?>
    <img src="paypal.gif" style="margin-right:20px;">
</div>

单击提交后,the _getParam()函数不会捕获视图为控制器中的实例变量设置的字符串“paypal”$this->payment_option_paypal

任何想法有什么问题以及如何解决这个问题?

4

2 回答 2

2

在您的phtml 页面中,您必须像这样使用

<div id="paypal" style="display: none;">
    <input type="hidden" name="paypalname" value="<?php echo $this->payment_option_paypal = "paypal"; ?>" id="paypalname"/>
    <img src="paypal.gif" style="margin-right:20px;">
</div>

控制器

function yourAction()
{
      if ($this->_request->isPost()) 
      {
         $paypalvalue=$this->_getParam('paypalname');
      }
}

我希望它对您有所帮助,如果您对我的回答有任何问题,请告诉我。

于 2012-08-07T05:55:17.770 回答
1

一个 div 不会提交数据,任何需要呈现为 html 的东西都必须被回显:

<form action="https://example.com/checkout/" name="info" method="post"> 
    <div id="payment">
        <div id="paypal>
            <?php echo $this->is_paypal_payment = true; ?><!-- maybe should be an input element of kind and echo the $this-> statement -->
        </div>
        <div id="credit_card>
            <?php echo $this->is_paypal_payment = false; ?><!-- maybe should be an input element of kind and echo the $this-> statement -->
        </div>
    </div>
</form>

再次回声:

<div id="paypal" style="display: none;">
    <?php echo $this->payment_option_paypal = "paypal"; ?>
    <img src="paypal.gif" style="margin-right:20px;">
</div>
于 2012-08-07T06:08:08.533 回答