Form Submit Using $_Post But No $_Post Data

I have created a Yii application for a client, which all works good with no problems locally and on my server which was used during testing. The client has moved the application to their server, which is where it will be hosted and when one variable on one form (there is only this form and a login form) is entered, then no $_POST are recorded by php. The field is an optional field.

Does anybody have any ideas what is causing this to happen?

The form view is below


<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

       'id'=>'clothing-knowledge-hub-form',

       'htmlOptions' => array('enctype' => 'multipart/form-data'),

       'enableAjaxValidation'=>false,

)); ?>


<p class="note">Fields with <span class="required">*</span> are required.</p>


<?php echo $form->errorSummary($model); ?>


<div class="row">

    <?php echo $form->labelEx($model,'headerText'); ?>

    <?php echo $form->textField($model,'headerText',array('size'=>60,'maxlength'=>255)); ?>

    <?php echo $form->error($model,'headerText'); ?><br/><br/>

</div>


<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'videoPath'); ?>

            Only enter a valid video embed path here. <br/>(This will overide the detail page image - image541x491 for this page)<br/>

    <?php echo $form->textField($model,'videoPath',array('size'=>60,'maxlength'=>255)); ?>

    <?php echo $form->error($model,'videoPath'); ?><br/><br/>

</div>




<div class="row">

    <?php echo $form->labelEx($model,'bodyText'); ?>

    <?php echo $form->textArea($model,'bodyText',array('rows'=>6, 'cols'=>50)); ?>


    <?php echo $form->error($model,'bodyText'); ?><br/>

</div>





<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'findOutMore'); ?>

            This will enable the 'Find Out More' button on the detail page.<br/> To enable it, please enter a valid url <?php //(include http:// or https://)?>

    <?php echo $form->textField($model,'findOutMore',array('size'=>60,'maxlength'=>510)); ?>

    <?php echo $form->error($model,'findOutMore'); ?>

            <br/><br/>

</div>


<div class="row">

    <?php echo $form->labelEx($model,'referencesText'); ?>

    <?php echo $form->textArea($model,'referencesText',array('rows'=>4, 'cols'=>100)); ?>


    <?php echo $form->error($model,'referencesText'); ?>

</div>




<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'image300x226'); ?>Please ensure all images are optimised, (max file size 1mb) and are either jpg, jpeg, pngs or gif.<br/>

    <?php echo $form->fileField($model,'image300x226',array('size'=>60,'maxlength'=>510)); ?><br/>

    <?php echo $form->error($model,'image300x226'); ?>

            <?php echo 'Existing image file name: '.$model['image300x226'];?><br/>

            <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/<?php echo $model['image300x226'];?>"><br/><br/>

</div>


<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'image300x473');?>Please ensure all images are optimised, (max file size 1mb) and are either jpg, jpeg, pngs or gif.<br/>

    <?php echo $form->fileField($model,'image300x473',array('size'=>60,'maxlength'=>510)); ?><br/>

    <?php echo $form->error($model,'image300x473'); ?>

            <?php echo 'Existing image file name: '.$model['image300x473'];?><br/>

            <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/<?php echo $model['image300x473'];?>"><br/><br/>

</div>


<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'image541x491').' Detail Page Image'; ?><br/>Please ensure all images are optimised, (max file size 1mb) and are either jpg, jpeg, pngs or gif. 

    <?php echo $form->fileField($model,'image541x491',array('size'=>60,'maxlength'=>510)); ?><br/>

    <?php echo $form->error($model,'image541x491'); ?>

            <?php echo 'Existing image file name: '.$model['image541x491'];?><br/>

            <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/<?php echo $model['image541x491'];?>"><br/><br/>

</div>


<div class="row">

            <br/>

    <?php echo $form->labelEx($model,'imageCredit'); ?>

            Html hyper links must include http:// or will result in a broken link<br/>

    <?php echo $form->textArea($model,'imageCredit',array('rows'=>6, 'cols'=>50)); ?>


    <?php echo $form->error($model,'imageCredit'); ?><br/>

</div>


<div class="row buttons">

    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

</div>

 <?php $this->endWidget(); ?>

 </div><!-- form -->

The controller action is below




public function actionUpdate($id)

{

    $model=$this->loadModel($id);


    // Uncomment the following line if AJAX validation is needed

    // $this->performAjaxValidation($model);

    echo Yii::trace(CVarDumper::dumpAsString($_POST), 'vardump');

    if(isset($_POST['ClothingKnowledgeHub']))

    {

        $model->setAttributes($_POST['ClothingKnowledgeHub']);


                    $file1 = CUploadedFile::getInstance($model, 'image300x226');

                    if($file1 != null){

                        $uniqueId = uniqid();

                        //$extra = Yii::app()->fileName->fileName();

                        $model->image300x226 = $uniqueId.'-'.$file1->name;

                    }


                    $file2 = CUploadedFile::getInstance($model, 'image300x473');

                    if($file2 != null){

                        $uniqueId = uniqid();

                        $model->image300x473 = $uniqueId.'-'.$file2->name;

                    }


                    $file3 = CUploadedFile::getInstance($model, 'image541x491');

                    if($file3 != null){

                        $uniqueId = uniqid();

                        $model->image541x491 = $uniqueId.'-'.$file3->name;

                    }


                    if(strpos($model->findOutMore, 'http') === false){

                        $model->findOutMore = 'http://'.$model->findOutMore;

                    }

        if($model->save()){

                        if($file1 != null){

                            $file1->saveAs(dirname(__FILE__)."/../../images/".$model->image300x226);


                        }

                        if($file2 != null){

                            $file2->saveAs(dirname(__FILE__)."/../../images/".$model->image300x473);


                        }

                        if($file3 != null){   

                            $file3->saveAs(dirname(__FILE__)."/../../images/".$model->image541x491);


                        }

                        echo Yii::trace(CVarDumper::dumpAsString($_POST['ClothingKnowledgeHub']), 'var_dump');

            $this->redirect(array('view','id'=>$model->id));

                    }

                    else {

                    ?><script type="text/javascript"> window.alert("There has been a problem saving your changes, please try again.")</script>

                    <?php  

                    }


    }


    $this->render('update',array(

        'model'=>$model,

    ));

}

Thank you for your help

Hi,

Please can you point out specific fields which was not included on POST request.

You exceed the max POST size set in php.ini. You have a file upload field and the file is too big. If you would have CSRF validation enabled that would trigger an error about missing CSRF token. I’m writing about this for others reading this as they may have encountered this and couldn’t find the cause.

It is the find out more field and only this field.

The Max POST size is set to 100MB so I do not think it is that, and also nothing is POSTed at all, even with no files being uploaded.

I’d put that var_dump in the index.php file to narrow it down if it’s a PHP or Yii issue. Did you try altering the field name? Does it behave this way with any kind of value entered in that field?

nineinchnick, I done what you suggested and done a var_dump in the index.php page. It showed an empty array, so I think it is a php problem.

If I remove the ‘findOutMore’ field completely then it works OK.

I would compare the raw http requests you make when posting that form with and without that field.

The raw post data ($HTTP_RAW_POST_DATA) is always NULL. Even when the form works and the page redirects. What am I missing?

Try this:


echo file_get_contents("php://input");

But if you use multipart/form-data this wrapper is not available:

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data". (source)

Try to comment out this line temporarily:


'htmlOptions' => array('enctype' => 'multipart/form-data'),

Other tip: check the web server body limit value (e.g. Apache: LimitRequestBody)