Zend Framework Source Code Snippets

FCKEditor a Form Element

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
Create class FormRTE in library/Zend/Form/Element/
 
/**
 * Zend Framework
 * * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 * * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License */
 
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
 /**
 * Textarea form element
 * 
 * @category   Zend
 * @package    Zend_Form * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Textarea.php 8064 2008-02-16 10:58:39Z thomas $
 */class Zend_Form_Element_FormRTE extends Zend_Form_Element_Xhtml
{
    /**
     * Use formTextarea view helper by default
     * @var string     */
    public $helper = 'formRTE';
}
1
2
3
4
5
create in Zend/View/Helper the class Zend_View_Helper_FormRTE or use an other HelperPath
 
<?php
$view->setHelperPath(APPLICATION_PATH . '/helpers');
?>
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
44
4546
47
48
49
5051
52
53
54
5556
57
58
59
6061
62
63
64
6566
<?php 
 
/** 
 * Abstract class for extension 
 */ require_once 'Zend/View/Helper/FormElement.php'; 
 
/** 
 * FCKeditor PHP class 
 */ require_once 'formRTE/fckeditor/fckeditor.php'; 
 
 
/** 
 * Helper to generate a "textarea" element  * 
 * @category   Zend 
 * @package    Zend_View 
 * @subpackage Helper 
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)  * @license    http://framework.zend.com/license/new-bsd     New BSD License 
 */ 
class Zend_View_Helper_FormRTE extends Zend_View_Helper_FormElement 
{ 
    /**      * Generates a richtext element using FCKeditor. 
     * 
     * @access public 
     * 
     * @param string|array $name If a string, the element name.  If an      * array, all other parameters are ignored, and the array elements 
     * are extracted in place of added parameters. 
     * 
     * @param mixed $value The element value. 
     *      * @param array $attribs Attributes for the element tag. 
     * 
     * @return string The element XHTML. 
     */ 
    public function formRTE($name = null, $value = null, $attribs = null)     { 
        if(is_null($name) && is_null($value) && is_null($attribs)) { 
            return $this; 
        } 
                 $info = $this->_getInfo($name, $value, $attribs); 
        extract($info); // name, value, attribs, options, listsep, disable 
 
        $editor = new FCKeditor($name); 
                 // set variables
        $editor->BasePath    = 'http://localhost/xxxx/application/helpers/formRTE/fckeditor/' ; 
        $editor->ToolbarSet = empty($attribs['ToolbarSet']) ? 'Basic' : $attribs['ToolbarSet']; 
        $editor->Width        = empty($attribs['Width']) ? '50%' : $attribs['Width']; 
        $editor->Height        = empty($attribs['Height']) ? 250 : $attribs['Height'];         $editor->Value        = $value; 
         
        // set Config  
        $editor->Config['BaseHref'] = $editor->BasePath;
        $editor->Config['CustomConfigurationsPath'] = $editor->BasePath.'editor/fckconfig.js';         $editor->Config['SkinPath'] = $editor->BasePath.'editor/skins/silver/';         
        return $editor->createHtml(); 
         
    } 
         }
1
2
3
4
56
7
8
9
1011
You can add this element to your form like other form elements:
 
 
$myForm->addElement('formRTE', 'message', array(
                                                        'label'      => 'formRTE label:',                                                                                                    'required'   => true,
                                                                                                    'value'      => 'Salam, Schalom, Pax vobis <i>this string </i>is the value variable  of the View_Helper,<br/>
                                                                                                                 but i give this string to <b>form->addElement()</b> ',
                                                        'attribs'    => array('myattribute') 
                                                        )                         );

Comments

phuonghoathu phuonghoathu
4 months ago

I can't do it.

dark horse dark horse
2 months ago

hello
please denote the file names and directory structure for all files and folders that use in your tutorial I'm confusing now !!

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

You can use FCKEditor as a normal Form Element in Zend Framework with this snippet.

Snippet details

Created:
masod masod
1 year ago
Edited:
masod masod
1 year ago
Revision Id:
93
Edit Message:
Initial Release
Tags:
php fckeditor form
Comments:
2
Views:
626
Points:
1 (1 votes)

History

r93

Initial Release

masod masod
1 year ago
diff
r92

Initial Release

masod masod
1 year ago
diff
r91

Initial Release

masod masod
1 year ago
diff
r90

Initial Release

masod masod
1 year ago
diff
r89

Initial Release

masod masod
1 year ago