- 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
}
看看你是否得到這些值'var_dump($ option)' – webDev
改變它到你所說的並沒有改變。同樣的錯誤@ Fred-ii- – Kray
語法是'__construct()'。你應該更新你的問題然後 –