1

  • THIS IS UNSOLVED

I have a class that I've put together to do a CRUD for me. Here is the sections that are applicable to my issue.

I am returning the following errors.

[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

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

}

I have double checked my array values and everything looks spot on? Can someone maybe get a second set of eyes on it and see what they think?

Let me know if you need explanation or need to see any functions that are not listed.

errors are populating from code section

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

result from 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 Class Functions i am using.

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
    }
13
  • see if your are getting those values or not var_dump($option) Commented Apr 7, 2017 at 23:04
  • Changed it to what you put and nothing changed. same errors @Fred-ii- Commented Apr 7, 2017 at 23:08
  • the syntax is __construct(). you should update your question then Commented Apr 7, 2017 at 23:09
  • I realized that after I said it.. I changed it and now getting PHP Fatal error: Call to undefined function FormFields() Commented Apr 7, 2017 at 23:09
  • which is coming from the construct Commented Apr 7, 2017 at 23:09

2 Answers 2

2

I meant this (sorry if you did not understand the comments)

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

Similarly everywhere do same. To point a variable use $this keyword you should have that variable in your class.

Sign up to request clarification or add additional context in comments.

7 Comments

PHP Fatal error: Cannot redeclare class FormFields in /class/FormFields.php on line 18 (which is class FormFields { ...)
see uodated code, and if not solved then post your FormFields class code. post class FormFields { ...}
go to the chat i sent the block @webDev
you are declaring your class twice, remove if you are requiring or including the class FormFields { ...}
I am no longer getting that error. I am back to the orignal error. Unidenfied Index.
|
0

The Method below was intended to do a quick validation of the input field to create. This posed an issue, and ultimately deprecated this method.

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;

    }

When I was creating the makeEntireForm() method I was creating a

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

which I changed to the following.

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

by removing this "middle man method" I was able to accomplish my end results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.