首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用$_POST但没有$_POST数据的Yii表单提交

使用$_POST但没有$_POST数据的Yii表单提交
EN

Stack Overflow用户
提问于 2013-10-14 19:13:02
回答 1查看 7.7K关注 0票数 3

我已经为客户端创建了一个Yii应用程序,它在本地和我的服务器上都工作得很好,并且在测试期间使用。客户端已经将应用程序移动到他们的服务器上,服务器将托管应用程序,当输入一个表单(只有这个表单和一个登录表单)上的一个变量时,php不会记录任何$_POST。该字段是可选字段。

有谁知道是什么导致了这种情况的发生吗?

表单视图如下所示

代码语言:javascript
复制
<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 -->

控制器操作如下所示

代码语言:javascript
复制
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,
    ));
}

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2013-10-17 04:08:24

尝试将其添加到cactiveform小部件

代码语言:javascript
复制
'method'=>'Post',

这也可能会有所帮助。http://www.yiiframework.com/doc/api/1.1/CActiveForm

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19358909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档