2017-04-07 5 views
1

  • DIES IST UNSOLVED

ich eine Klasse, die ich zusammengestellt habe für mich eine CRUD zu tun. Hier sind die Abschnitte, die für mein Problem gelten.Klasse -> Array undefiniert Index PHP

Ich gebe die folgenden Fehler zurück.

[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 

Klasse

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____; 
    } 

} 

ich doppelt meine Array-Werte überprüft haben und alles sieht auf beschmutzen? Kann jemand vielleicht einen zweiten Blick darauf werfen und sehen, was sie denken?

Lassen Sie mich wissen, wenn Sie eine Erklärung benötigen oder Funktionen sehen müssen, die nicht aufgeführt sind.

Fehler von Codeabschnitt

// 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; 
} 

Ergebnis von 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 Klassenfunktionen bevöl ich verwende.

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

sehen Sie, ob Sie diese Werte erhalten oder nicht 'var_dump ($ option)' – webDev

+0

Geändert zu dem, was Sie setzen und nichts geändert. gleiche Fehler @ Fred-ii- – Kray

+0

die Syntax ist '__construct()'. Sie sollten Ihre Frage dann aktualisieren –

Antwort

0

Die folgende Methode sollte eine schnelle Validierung des zu erstellenden Eingabefeldes ermöglichen. Dies stellte ein Problem dar und verwarf diese Methode letztendlich.

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; 

    } 

Als ich die Schaffung der makeEntireForm() Verfahren I wurde ein

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

schaffen, die ich in die folgenden geändert.

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

durch Entfernen dieser "Mittelmann-Methode" konnte ich meine Endergebnisse erreichen.

2

Ich bedeutete dies (sorry, wenn Sie die Kommentare nicht verstehen)

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(
    //............... 
    //................. 

Ähnlich überall gleiche tun. Um auf eine Variable zu verweisen, verwenden Sie das Schlüsselwort $this. Sie sollten diese Variable in Ihrer Klasse haben.

+0

PHP Schwerwiegender Fehler: Kann Klasse FormFields nicht in /class/FormFields.php in Zeile 18 (das ist 'Klasse FormFields {...') – Kray

+0

Immer noch Getting fatal error redeclare. – Kray

+0

sehen Sie Code und wenn nicht gelöst dann buchen Sie Ihren 'FormFields' Klassencode. post 'class FormFields {...}' – webDev