$this->getRequest()->isPost() return false

折月煮酒 提交于 2021-02-09 01:20:57

问题


I'm working on an existing code who the last developer have created a form but without using a "$form", and the code is:

 public function indexAction() {
    .......

    $objRequest = $this->getRequest();
    var_dump($objRequest->isPost())  ==> all time return false
    if ($objRequest->isPost()) {

    $postedData = $objRequest->getPost();
    $inputData = new Zend_Filter_Input($this->filters, $this->validators,
                        $objRequest->getPost());

        $params = $this->getRequest()->getParams();
        if ($inputData->isValid()) {

   ..... 

and in the vie :

<?php $actionURL = $this->url(array(
'controller' => 'index',
'action'     => 'index',
'module'     => 'default',
));
?>

<form name="indexFormn" id="indexForm"  method="POST" action="<?php echo $actionURL; ?>">
<div class="AdminformDiv">
    <div class="errorbox">
        <?php
        if (!is_array($this->actionErrors)) {
            echo $this->actionErrors;
        }
        ?>
    </div>
    <div>
        <table border="0" cellpadding="0" cellspacing="0" style="width:700px">
            <tbody>
                <tr>
                    <td style="width:128px">Amount</td>
                    <td colspan="2">$ <?php echo $this->price;?> USD<td     style="width:270px">&nbsp;</td>
                </tr>
                <tr>

    .....

That means he don't use any form class but he do like the old php method but with zend,so all time he return false and I can't fix or detect where is the problem?


回答1:


I've just had a similar problem and found the solution after hours of searching. Check whether your opening and closing form tags are fulling enclosing the form. I accidentally forgot to remove an additional closing form tag that I previously put in the view file.

I'm not hundred percent sure how this affected my form but the additional closing form tag changed my method to 'get' even though I set it to post, thus when I hit submit, it would skip right passed the validation part.

I hope this helps.




回答2:


The form has method="GET" - it's not a POST form, so that's why isPost() is returning false. Change that to method="POST" and it should be fine.




回答3:


In my case the problem derived from nginx config using zend:

The missing $args was not populating the query string:

I change:

try_files $uri $uri/ =404;

To:

try_files $uri $uri/ /index.php?$args;

The question related about this answer has a more detailed explanation about that. But basically:

Unlike with rewrite, $args are not automatically preserved if the fallback is not a named location. If you need args preserved, you must do so explicitly:



来源:https://stackoverflow.com/questions/18363991/this-getrequest-ispost-return-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!