2017-04-07 44 views
1

  • THIS IS未解

我有我已经把为我做一个CRUD类。以下是适用于我的问题的部分。类 - >阵列未定义指数PHP

我回来了以下错误。

[07-Apr-2017 15:45:40 America/Los_Angeles] PHP Notice: Undefined index: placeholder in class/LeadStages.php on line 88 
[07-Apr-2017 15:45:40 America/Los_Angeles] PHP Notice: Undefined index: id in class/LeadStages.php on line 90 
[07-Apr-2017 15:45:40 America/Los_Angeles] PHP Notice: Undefined index: type in class/LeadStages.php on line 91 
[07-Apr-2017 15:45:40 America/Los_Angeles] PHP Notice: Undefined index: maxchar in class/LeadStages.php on line 93 

class LeadStage { 

    /* 
    * Create LeadStage. You will need to include the "LeadStage" 
    * in which is being created, the date created, 
    * time created, and the user who created it. 
    */ 

    function __construct() { 
     $this->FormFields = new FormFields; 
    } 

    // Input Field -> Stage 
    function addInputError_New_Element($option) { 
     var_dump($option); 
     $element = $this->FormFields->InputError_NEW(
      $Error = $option['error'], 
      $Value = $option['value'], 
      $PlaceHolder = $option['placeholder'], 
      $InputName = $option['name'], 
      $InputID = $option['id'], 
      $InputType = $option['type'], 
      $InputLabel = $option['label'], 
      $MaxChar = $option['maxchar'], 
      $required = $option['required'] 
     ); 
     return $element; 
    } 

    // Select Option -> Status 
    function addSelectError_New_Element($option) { 

     $element = $this->FormFields->SelectError_NEW(
      $ErrorMSG = $options['error'], 
      $InputLabel = $option['label'], 
      $Class = $option['class'], 
      $DataTargetDIVID = $option['targetid'], 
      $SelectName = $option['name'], 
      $SelectArray = $option['array'], 
      $Value = $option['value'], 
      $required = $option['required'], 
      $Value = FALSE 
     ); 

     return $element; 

    } 

    function addElementToForm($option) { 

     if($option['FormField'] = 'stage') { 

      // Build our Markup to input our new stage. 

      $element = $this->addInputError_New_Element($option); 

     } 
     elseif($option['FormField'] = 'status') { 

      // Build our Markup for selecting our status. 
      $element = $this->addSelectError_New_Element($option); 

     } 

     return $element; 

    } 

    function makeEntireForm() { // next stage is to forget hard coding instead pass in array of elments you want made and cycle through array. 

      /* 
      * Create Input field -> Stage 
      */ 
      $entireForm = ''; 
      $option = array(
       'FormField'  => 'stage', 
       'error'   => FALSE, 
       'value'   => FALSE, 
       'placeholder' => 'Stage (ie; Scheduled Inspection)', 
       'name'   => 'stage', 
       'id'   => FALSE, 
       'type'   => 'text', 
       'label'   => 'Stage', 
       'maxchar'  => 50, 
       'required'  => TRUE 
      ); 
      // Build Element 
      $entireForm .= $this->addElementToForm($option); 

      /* 
      * Create Input field -> Status 
      */ 
      $arrayvalues = array('Test','Test2'); 
      $option = array(
        'FormField' => 'status', 
        'error'  => FALSE, 
        'label'  => 'Status', 
        'class'  => FALSE, 
        'targetid' => FALSE, 
        'name'  => 'status', 
        'array'  => $arrayvalues, 
        'value'  => FALSE, 
        'required' => TRUE 
       ); 
      // Build Element 
      $entireForm .= $this->addElementToForm($option); 

     return $entireForm; 

    } 

    function viewLeadStagesMarkup($title,$action,$return) { 

     $Form = $this->makeEntireForm(); 

     $HTML____ = NULL; 

     $HTML____ .= '<form class="form-horizontal" action="'. $action .'" method="post">' . 
        '<div class="panel panel-info">' . 
        '<div class="panel-heading">' . 
        '<h3 class="panel-title">'. $title .'</h3>' . 
        '</div>' . 
        '<div class="panel-body">' . 
        '<p>WARNING: Page under maintenance. Please do not use. Hit cancel and go back.</p>' . 
        '<div class="row">' . 
        '<div class="col-md-12 col-lg-12">' . 
        $Form . 
        '</div>' . 
        '</div>' . 
        '</div>' . 
        '<div class="panel-footer">' . 
        '<a href="'.$return.'" type="button" class="btn btn-sm btn-warning"><i class="#"></i>Cancel</a> ' . 
        '<div class="pull-right">' . 
        '<button type="submit" class="btn btn-sm btn-success">Create</button>' . 
        '</div>' . 
        '</div>' . 
        '</div>' . 
        '</form>'; 

     return $HTML____; 
    } 

} 

我有双重检查我的数组值,一切看起来现货吗?有人可能会得到第二套眼睛,看看他们的想法吗?

如果您需要说明或需要查看任何未列出的功能,请告知我们。

误差从代码部分填充

// Input Field -> Stage 
function addInputError_New_Element($option) { 
    var_dump($option); 
    $element = $this->FormFields->InputError_NEW(
     $Error = $option['error'], 
     $Value = $option['value'], 
     $PlaceHolder = $option['placeholder'], 
     $InputName = $option['name'], 
     $InputID = $option['id'], 
     $InputType = $option['type'], 
     $InputLabel = $option['label'], 
     $MaxChar = $option['maxchar'], 
     $required = $option['required'] 
    ); 
    return $element; 
} 

结果从var_dump($option);

array(10) { ["FormField"]=> string(5) "stage" ["error"]=> bool(false) ["value"]=> bool(false) ["placeholder"]=> string(31) "Stage (ie; Scheduled Inspection" ["name"]=> string(5) "stage" ["id"]=> bool(false) ["type"]=> string(4) "text" ["label"]=> string(5) "Stage" ["maxchar"]=> int(50) ["required"]=> bool(true) } array(9) { ["FormField"]=> string(5) "stage" ["error"]=> bool(false) ["label"]=> string(6) "Status" ["class"]=> bool(false) ["targetid"]=> bool(false) ["name"]=> string(6) "status" ["array"]=> array(2) { [0]=> string(4) "Test" [1]=> string(5) "Test2" } ["value"]=> bool(false) ["required"]=> bool(true) } 

我使用FormFields类函数。

function InputError_NEW($Error, $Value, $PlaceHolder, $InputName, $InputID, $InputType, $InputLabel, $MaxChar,$required) { 
     $output = '<div class="control-group">'; 
     if (!empty($Error)) { 
       $output .='<label class="control-label" for="inputError"> 
        <i style="color:red" class="fa fa-times-circle-o"> 
         <b>'.$Error.'</b> 
        </i> 
       </label>'; 
     } 
     $output .='<label class="control-label">' . $InputLabel . '</label>' . 
       '<div class="controls">' . 
       '<input class="form-control"'; 
        if (!empty($InputID)) { 
         $output .= ' id="' . $InputID . '"'; 
        } 
        if (!empty($InputName)) { 
         $output .= ' name="' . $InputName . '"'; 
        } 
        if (!empty($InputType)) { 
         $output .= ' type="' . $InputType . '"'; 
        } 
        if (!empty($PlaceHolder)) { 
         $output .= ' placeholder="' . $PlaceHolder . '"'; 
        } 
        if (!empty($Value)) { 
         $output .= ' value="' . $Value . '"'; 
        } 
        if (!empty($MaxChar)) { 
         $output .=' maxlength="'. $MaxChar . '"'; 
        } 
        if ($required) { 
         $output .= ' required'; 
        } 
        $output .= '>' . 
       '</div>' . 
       '</div>'; 
     return $output; // you will have to echo ($output); in the HTML file 
    } 

    function SelectError_NEW($Error, $InputLabel, $Class, $DataTargetDIVID, $SelectName, $SelectArray, $Value) { 
     $output = '<div class="control-group">'; 
     if (!empty($Error)) { 
       $output .='<label class="control-label" for="inputError"> 
        <i style="color:red" class="fa fa-times-circle-o"> 
         <b>'.$Error.'</b> 
        </i> 
       </label>'; 
     } 
     $output .='<label class="control-label">' . $InputLabel . '</label>' . 
       '<div class="controls">' . 
       '<select class="form-control ' . $Class . '" data-target="' . $DataTargetDIVID .'" name="' . $SelectName .'"'; 
       if ($required) { 
       $output .= ' required'; 
       } 
       $output .='> 
        <option value="">-- Select One --</option> 
        '.makeOptions($SelectArray, $Value).' 
       </select>' . 
       '</div>' . 
       '</div>'; 
     return $output; // you will have to echo ($output); in the HTML file 
    } 
+0

看看你是否得到这些值'var_dump($ option)' – webDev

+0

改变它到你所说的并没有改变。同样的错误@ Fred-ii- – Kray

+0

语法是'__construct()'。你应该更新你的问题然后 –

回答

0

下面的方法旨在快速验证要创建的输入字段。这提出了一个问题,并最终弃用这种方法。

function addElementToForm($option) { 
     if($option['FormField'] = 'stage') { 

      // Build our Markup to input our new stage. 
      $element = $this->addInputError_New_Element($option); 

     } 
     if($option['FormField'] = 'status') { 
      // Build our Markup for selecting our status. 
      $element = $this->addSelectNoBlank_New_Element($option); 

     } 

     return $element; 

    } 

当我创建makeEntireForm()方法我创建一个

$entireForm .= $this->addElementToForm($stage_option); 

我改变为如下。

$entireForm .= $this->addInputError_New_Element($stage_option); 

通过删除这个“中间人的方法”我能够完成我的最终结果。

2

我的意思是这个(抱歉,如果你不明白的注释)

class LeadStage { 
    private $my_object; 
    function __construct() { 
     $this->my_object = new FormFields(); 
    } 

    // Input Field -> Stage 
    function addInputError_New_Element($option) { 
     //$FormFields = new FormFields(); 
     $element = $this->my_object->InputError_NEW(
    //............... 
    //................. 

同样无处不在做相同的。要指出一个变量使用$this关键字,你应该在你的班级中使用该变量。

+0

PHP致命错误:无法在第18行(这是类FormFields {...') – Kray

+0

重新声明classclassFields在/class/FormFields.php仍然开始致命错误。 – Kray

+0

看到uodated代码,如果没有解决,然后发布您的'FormFields'类代码。 post class'FormFields {...}' – webDev