2013-12-09 31 views
0

我想從$ _POST獲取單個數據,表單中的字段名爲「parametro」,並將其保存在$ _POST ['Caracterizacion']上,我想要得到這個「parametro」並將其保存爲var的字符串,如何獲取這些數據?

+1

您應該嘗試使用:print_r($ _ POST)來查看有關POST參數的信息。順便說一句,你可以嘗試$ _POST ['Caracterizacion'] ['parametro']來獲得它。 – secretlm

+0

事實上,確實有幫助,謝謝,它的工作原理。 – nosthertus

回答

1
$_POST['Caracterizacion']['parametro'] 
+0

做了這項工作,謝謝 – nosthertus

0

所以窗體上的字段是parametro?我將承擔下列HTML:

<input type="text" name="parametero" id="param_1"/> 

在這種情況下,您就可以訪問內容的那場像這樣:

$var = $_POST['parametero']; 

這是假設表單元素的方法屬性,這個輸入元素在設置爲POST

如果我假設不正確,請進一步闡述並提供至少您的html。

+0

它給了我一個錯誤「未定義索引:Parametro」,是的,表單上的字段是parametro – nosthertus

+0

它是區分大小寫的 – Zarathuztra

+0

仍然給我「未定義索引:parametro」 – nosthertus

0

本所認爲:

<div class="form"> 

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'caracterizacion-form', 
    // Please note: When you enable ajax validation, make sure the corresponding 
    // controller action is handling ajax validation correctly. 
    // There is a call to performAjaxValidation() commented in generated controller code. 
    // See class documentation of CActiveForm for details on this. 
    '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,'parametro'); ?> 
     <?php echo $form->textField($model,'parametro',array('size'=>60,'maxlength'=>256)); ?> 
     <?php echo $form->error($model,'parametro'); ?> 
    </div> 




    <div class="row buttons"> 
     <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> 
    </div> 

<?php $this->endWidget(); 

?> 



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

,這是從控制器動作

public function actionCreate() 
    { 
     $model=new Caracterizacion; 

     // Uncomment the following line if AJAX validation is needed 
     // $this->performAjaxValidation($model); 

     if(isset($_POST['Caracterizacion'])) 
     { 
      $model->attributes=$_POST['Caracterizacion']; 
      if($model->save()) 
      { 
       $variable="hola"; 
       Caracterizacion::model()->columna($variable); 
       $this->redirect(array('view','id'=>$model->id)); 
      } 
      if($model->save() == false) 
       var_dump($model->errors); 
     } 

     $this->render('create',array(
      'model'=>$model, 
     )); 
    } 

你可以看到即時製作一個名爲與內容「HOLA」,其被帶到變量var在模型上做的一個類,現在它工作,但事情是,我想用$ _POST上的一個元素替換「hola」字符串,當我用$ _POST ['Caracterizacion']替換它時,它會給我一個錯誤「數組到字符串轉換」,所以我不知道該怎麼做,這就是爲什麼我問如何得到只有1元素fr om $ _post