Pluf Framework

Sign in or create your account | Project List | Help

Pluf Framework Git Source Tree

Root/src/Pluf/Form/Widget/TextareaInput.php

1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of Plume Framework, a simple PHP Application Framework.
6# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
7#
8# Plume Framework is free software; you can redistribute it and/or modify
9# it under the terms of the GNU Lesser General Public License as published by
10# the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
13# Plume Framework is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24/**
25 * Textarea.
26 */
27class Pluf_Form_Widget_TextareaInput extends Pluf_Form_Widget
28{
29
30    public function __construct($attrs=array())
31    {
32        $this->attrs = array_merge(array('cols' => '40', 'rows' => '10'),
33                                   $attrs);
34    }
35
36    /**
37     * Renders the HTML of the input.
38     *
39     * @param string Name of the field.
40     * @param mixed Value for the field, can be a non valid value.
41     * @param array Extra attributes to add to the input form (array())
42     * @return string The HTML string of the input.
43     */
44    public function render($name, $value, $extra_attrs=array())
45    {
46        if ($value === null) $value = '';
47        $final_attrs = $this->buildAttrs(array('name' => $name),
48                                         $extra_attrs);
49        return new Pluf_Template_SafeString(
50                       sprintf('<textarea%s>%s</textarea>',
51                               Pluf_Form_Widget_Attrs($final_attrs),
52                               htmlspecialchars($value, ENT_COMPAT, 'UTF-8')),
53                       true);
54    }
55}

Archive Download this file

Branches:
develop
master