public function input($name, $options = array())
    {
        $options += array(
            "type"  => "text",
            "id"    => $this->id($name),
            "name"  => $this->name($name),
            "error" => true,
            "class" => "",
            "value" => "",
            "label" => null
        );

        $currentValue = $this->getCurrentValue($options['name']);

        $errorHtml = "";
        $fieldHasErrors = false;

        if (!is_null($this->associatedEntity)) {
            // Checkboxes may be posted has data[name][0] and therefore
            // we need to remove it to get the absolute field name.
            $validationName = $options["type"] === "checkbox" ?
                preg_replace('/\[\d+\]$/', '', $name) :
                $name;

            if ($this->associatedEntity->hasErrors($validationName)) {
                if ((bool)$options['error']) {
                    $errorHtml = $this->generateInlineErrors($validationName);
                }
                $fieldHasErrors = true;
                $options['class'] .= " error ";
            }
        }
        unset($options["error"]);

        $label = "";
        if (!is_null($options['label'])) {
            $labelOptions = array(
                "for"    => $options["id"],
                "class" => $fieldHasErrors ? "error" : "",
                "label" => $options["label"],
            );

            $label .= $this->label($options['name'], $labelOptions);
        }
        unset($options['label']);

        switch (strtolower($options['type'])) {
            case "textarea":
                return $label . "\n" . $this->generateTextarea($options, $currentValue) . $errorHtml . "\n";
            case "select":
                return $label . "\n" . $this->generateSelect($options, $currentValue) . $errorHtml . "\n";
            case "radio":
                return $this->generateRadio($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "checkbox":
                return $this->generateCheckbox($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "hidden":
                return $label . "\n" . $this->generateHidden($options, $currentValue) . $errorHtml . "\n";
            default:
                return $label . "\n" . $this->generateTextinput($options, $currentValue) . $errorHtml . "\n";
        }
    }
public function input($name, $options = array())
    {
        $options += array(
            "type"  => "text",
            "id"    => $this->id($name),
            "name"  => $this->name($name),
            "error" => true,
            "class" => "",
            "value" => "",
            "label" => null
        );

        $currentValue = $this->getCurrentValue($options['name']);

        $errorHtml = "";
        $fieldHasErrors = false;

        if (!is_null($this->associatedEntity)) {
            // Checkboxes may be posted has data[name][0] and therefore
            // we need to remove it to get the absolute field name.
            $validationName = $options["type"] === "checkbox" ?
                preg_replace('/\[\d+\]$/', '', $name) :
                $name;

            if ($this->associatedEntity->hasErrors($validationName)) {
                if ((bool)$options['error']) {
                    $errorHtml = $this->generateInlineErrors($validationName);
                }
                $fieldHasErrors = true;
                $options['class'] .= " error ";
            }
        }
        unset($options["error"]);

        $label = "";
        if (!is_null($options['label'])) {
            $labelOptions = array(
                "for"    => $options["id"],
                "class" => $fieldHasErrors ? "error" : "",
                "label" => $options["label"],
            );

            $label .= $this->label($options['name'], $labelOptions);
        }
        unset($options['label']);

        switch (strtolower($options['type'])) {
            case "textarea":
                return $label . "\n" . $this->generateTextarea($options, $currentValue) . $errorHtml . "\n";
            case "select":
                return $label . "\n" . $this->generateSelect($options, $currentValue) . $errorHtml . "\n";
            case "radio":
                return $this->generateRadio($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "checkbox":
                return $this->generateCheckbox($options, $currentValue) . $errorHtml . "\n" . $label . "\n";
            case "hidden":
                return $label . "\n" . $this->generateHidden($options, $currentValue) . $errorHtml . "\n";
            default:
                return $label . "\n" . $this->generateTextinput($options, $currentValue) . $errorHtml . "\n";
        }
    }
public function input ( $ name , $ options = array ( ) ) { $ options += array ( "type" => "text" , "id" => $ this -> id ( $ name ) , "name" => $ this -> name ( $ name ) , "error" => true , "class" => "" , "value" => "" , "label" => null ) ; $ currentValue = $ this -> getCurrentValue ( $ options [ 'name' ] ) ; $ errorHtml = "" ; $ fieldHasErrors = false ; if ( ! is_null ( $ this -> associatedEntity ) ) { // Checkboxes may be posted has data[name][0] and therefore // we need to remove it to get the absolute field name. $ validationName = $ options [ "type" ] === "checkbox" ? preg_replace ( '/\[\d+\]$/' , '' , $ name ) : $ name ; if ( $ this -> associatedEntity -> hasErrors ( $ validationName ) ) { if ( ( bool ) $ options [ 'error' ] ) { $ errorHtml = $ this -> generateInlineErrors ( $ validationName ) ; } $ fieldHasErrors = true ; $ options [ 'class' ] .= " error " ; } } unset ( $ options [ "error" ] ) ; $ label = "" ; if ( ! is_null ( $ options [ 'label' ] ) ) { $ labelOptions = array ( "for" => $ options [ "id" ] , "class" => $ fieldHasErrors ? "error" : "" , "label" => $ options [ "label" ] , ) ; $ label .= $ this -> label ( $ options [ 'name' ] , $ labelOptions ) ; } unset ( $ options [ 'label' ] ) ; switch ( strtolower ( $ options [ 'type' ] ) ) { case "textarea" : return $ label . "\n" . $ this -> generateTextarea ( $ options , $ currentValue ) . $ errorHtml . "\n" ; case "select" : return $ label . "\n" . $ this -> generateSelect ( $ options , $ currentValue ) . $ errorHtml . "\n" ; case "radio" : return $ this -> generateRadio ( $ options , $ currentValue ) . $ errorHtml . "\n" . $ label . "\n" ; case "checkbox" : return $ this -> generateCheckbox ( $ options , $ currentValue ) . $ errorHtml . "\n" . $ label . "\n" ; case "hidden" : return $ label . "\n" . $ this -> generateHidden ( $ options , $ currentValue ) . $ errorHtml . "\n" ; default : return $ label . "\n" . $ this -> generateTextinput ( $ options , $ currentValue ) . $ errorHtml . "\n" ; } }
Generates an input field
@param  string $name
@param  array  $options
@return string
Generates an input field