Forum

Thread tagged as: Problem, Api

Form Class Query

Hi,

Looking to use the Editor with a texarea field.

It's not working at the moment. Here's my code:

echo $Form->textarea_field('courseDeets','Details',isset($details['courseDeets'])?$details['courseDeets']:false,"description",true);
Harry Ray

Harry Ray 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

I'm not sure I understand the context, can you post more information about what you are trying to do plus your Diagnostics Report and template.

Hi Rachel,

In your docs for the Form class in the API, it says that I can use an editor with the textarea field. That's what I'm trying to do!

Here is my diagnostics report:

PERCH INFORMATION

Perch: 2.8.31
Production mode: Production (100)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_shop_paypal (1.2.3), perch_forms (1.8.3), perch_blog (5.0), perch_comments (1.2), perch_members (1.5), perch_twitter (3.5.1)
DB driver: PDO
DB tables: perch2_blog_authors (4), perch2_blog_comments (2), perch2_blog_index (199), perch2_blog_posts (2), perch2_blog_posts_to_tags (14), perch2_blog_sections (1), perch2_blog_tags (8), perch2_blogs (1), perch2_categories (1), perch2_category_counts (0), perch2_category_sets (3), perch2_comments (9), perch2_comments_votes (0), perch2_content_index (3367), perch2_content_items (1089), perch2_content_regions (307), perch2_courses (1), perch2_forms (2), perch2_forms_responses (12), perch2_members (0), perch2_members_forms (1), perch2_members_member_tags (0), perch2_members_sessions (1), perch2_members_tags (0), perch2_navigation (4), perch2_navigation_pages (52), perch2_page_templates (20), perch2_pages (73), perch2_resource_log (3640), perch2_resource_tags (6), perch2_resources (553), perch2_resources_to_tags (6), perch2_settings (37), perch2_shop_categories (11), perch2_shop_courses (2), perch2_shop_log (0), perch2_shop_orders (0), perch2_shop_product_options (0), perch2_shop_products (2), perch2_shop_products_to_categories (0), perch2_shop_products_to_courses (0), perch2_twitter_scheduled_tweets (0), perch2_twitter_settings (1), perch2_twitter_tweets (797), perch2_user_passwords (0), perch2_user_privileges (81), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (8)
Users: 8
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_blog',
        'perch_members',
        'perch_twitter',
        'perch_forms',
        'perch_comments',
        'perch_shop_paypal'
    );
Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
Scheduled tasks for perch_comments: delete_spam_comments (1440 mins)
Scheduled tasks for perch_twitter: post_tweets (1 mins), update_tweets (30 mins)
Editor plug-ins: markitup
H1: b919ed60f474a028cb34fa92d00f85a8
L1: decc131a5977ddd7a8d783c56351db03
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.25: done
latest_version: 2.8.15
on_sale_version: 2.8.31
headerScheme: light
perch_blog_site_name:
perch_blog_post_url: /news/{postSlug}
perch_blog_slug_format: {postTitle}-{postID}
perch_blog_akismet_key:
perch_blog_max_spam_days: 0
dashboard: 0
hide_pwd_reset: 0
content_hideNonEditableRegions: 1
content_frontend_edit: 0
perch_blog_comment_notify: 1
perch_blog_update: 5.0.1
perch_members_update: 1.4
perch_twitter_update: 3.5
perch_members_login_page: /members/login.php?r={returnURL}
update_2.8.31: done
perch_shop_update: 1.0.6
perch_comments_akismet_key:
perch_comments_max_spam_days: 0
perch_shop_price_tax_mode: exc
perch_shop_site_url: https://
perch_shop_product_url: /training-and-courses/product.php?s={productSlug}
perch_shop_default_currency:
perch_shop_reporting_currency:
perch_shop_invoice_number_format: Invoice%d
perch_shop_display_oos: 1
perch_shop_paypal_email: info@activegloucestershire.org
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: activeglos_user
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: admin_activeglos
PERCH_DB_PREFIX: perch2_
PERCH_TZ: UTC
PERCH_EMAIL_FROM: jamesh@thirdfloordesign.co.uk
PERCH_EMAIL_FROM_NAME: Active Gloucestershire
PERCH_LOGINPATH: /cms
PERCH_PATH: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net/cms
PERCH_CORE: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net/cms/core
PERCH_RESFILEPATH: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net/cms/resources
PERCH_RESPATH: /cms/resources
PERCH_HTML5: 1
PERCH_DEBUG: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net/cms/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: textile
HOSTING SETTINGS

PHP: 5.4.13
Zend: 2.4.0
OS: Linux
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: 5.5.30
MySQL server: 5.5.30
Free disk space: 5.33 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, zlib, bz2, calendar, ctype, hash, filter, ftp, gettext, gmp, SPL, iconv, pcntl, readline, Reflection, session, standard, shmop, SimpleXML, sockets, mbstring, tokenizer, xml, cgi-fcgi, curl, dom, fileinfo, gd, imagick, imap, json, ldap, exif, mcrypt, mysql, mysqli, odbc, PDO, pdo_mysql, PDO_ODBC, pdo_sqlite, Phar, snmp, sqlite3, wddx, xmlreader, xmlrpc, xmlwriter, xsl, zip, mhash, ionCube Loader
GD: Yes
ImageMagick: Yes
PHP max upload size: 128M
PHP max form post size: 8M
PHP memory limit: 128M
Total max uploadable file size: 8M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
PATH: /sbin:/usr/sbin:/bin:/usr/bin
PP_CUSTOM_PHP_INI: /var/www/vhosts/system/ag.thirdfloordigital.net/etc/php.ini
PP_CUSTOM_PHP_CGI_INDEX: fastcgi
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
REQUEST_URI: /cms/core/settings/diagnostics/?extended
QUERY_STRING: extended
REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.0
GATEWAY_INTERFACE: CGI/1.1
REMOTE_PORT: 33775
SCRIPT_FILENAME: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net/cms/core/settings/diagnostics/index.php
SERVER_ADMIN: jamesh@thirdfloordesign.co.uk
DOCUMENT_ROOT: /var/www/vhosts/thirdfloordigital.net/ag.thirdfloordigital.net
REMOTE_ADDR: 88.104.182.171
SERVER_PORT: 80
SERVER_ADDR: 205.186.165.244
SERVER_NAME: ag.thirdfloordigital.net
SERVER_SOFTWARE: Apache
SERVER_SIGNATURE: <address>Apache Server at ag.thirdfloordigital.net Port 80</address>
HTTP_COOKIE: cmsa=1; PHPSESSID=ga7mks5ssvseoigc2ufrv1khc7
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate, sdch
HTTP_REFERER: https://ag.thirdfloordigital.net/cms/core/settings/diagnostics/
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_CONNECTION: close
HTTP_X_ACCEL_INTERNAL: /internal-nginx-static-location
HTTP_X_FORWARDED_FOR: 88.104.182.171
HTTP_X_REAL_IP: 88.104.182.171
HTTP_HOST: ag.thirdfloordigital.net
UNIQUE_ID: V5p8r826pfQAAHKjckUAAAAB
FCGI_ROLE: RESPONDER
PHP_SELF: /cms/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1469742255.2069
REQUEST_TIME: 1469742255

and the file that I'm using:

<?php



    # Side panel
    echo $HTML->side_panel_start();
    echo $HTML->para('Add a new course here.');
    echo $HTML->side_panel_end();


    # Main panel
    echo $HTML->main_panel_start(); 
    include('_subnav.php');

    echo $HTML->heading1('Editing a Course');

    if ($message) echo $message;

    echo $HTML->heading2('Course details');


    echo $Form->form_start();

        echo $Form->text_field('courseTitle', 'Title',isset($details['courseTitle'])?$details['courseTitle']:false);
         if(is_object($Course)) {
            echo $Form->text_field('courseRef', 'Ref',isset($details['courseRef'])?$details['courseRef']:false);
            echo $Form->text_field('courseSlug', 'URL',isset($details['courseSlug'])?$details['courseSlug']:false);
            echo $Form->textarea_field('courseDeets', 'Details',isset($details['courseDeets'])?$details['courseDeets']:false,"description",true);
            echo $Form->text_field('coursePrice', 'Price',isset($details['coursePrice'])?$details['coursePrice']:false);
        }
        echo $Form->hidden('courseID', isset($details['courseID'])?$details['courseID']:false);



        echo $Form->submit_field('btnSubmit', 'Save', $API->app_path().'/courses/');


    echo $Form->form_end();

    echo $HTML->main_panel_end();

?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

To use an editor, it's just a case of getting the correct class onto the textarea. The JavaScript then does the rest.

Hi Drew,

Are you able to explain what you mean? I followed the docs (at least, I thought I had), by using a boolean for the last parameter of the textarea_field call.

Thanks, Harry

Drew McLellan

Drew McLellan 2638 points
Perch Support

By default the field will use the default editor, which is legacy behaviour.

You can pass in a tag object so that a bunch of options can be set. If you have a template from the user, you can use that tag - if not you can build your own:

$Tag = new PerchXMLTag('<perch:content id="foo" type="textarea" editor="markitup" />');

echo $Form->textarea_field('foo', 'Foo', '123', null, $Tag);

Hi Drew,

I'm using this code:

$Tag = new PerchXMLTag('<perch:shop id="courseDeets" type="textarea" editor="markitup" textile="true" html="true" />'); 

echo $Form->textarea_field('courseDeets', 'Details',isset($details['courseDeets'])?$details['courseDeets']:false, null, $Tag);

(I've also used <perch:content instead of shop, but with no difference in the outcome).

Here's what's being output:

<textarea id="courseDeets" name="courseDeets" class="text  large markitup textile" rows="6" cols="40"></textarea>

I'm looking for the editor with the top bar where you can choose Bold, Italic, Underline etc.

Currently, the textarea field is just a textarea field, with no editor.

Thanks, Harry

Drew McLellan

Drew McLellan 2638 points
Perch Support

The output looks correct to me. Is it otherwise working like you'd expect?

Hi Drew,

No - it's outputting just a textarea without the editor.

Thanks, Harry

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, but doesn't it work otherwise?

The textarea works.

However, I need it to be a textile (or editor, whichever has the WYSIWYG).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I'll see if I can figure out a solution.

Hi Drew,

Did we get any further with this?

Thanks, Harry

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, without a template there's no field types to kick the JavaScript into action.

So how would you suggest that I get this to work?

I'm following your docs, as far as I'm aware.

Hi Drew,

In your docs for the $Form API Class, the textarea_field method is documented like this:

PerchAPI_Form::textarea_field(string $id, string $label [, string $value, string $classname, boolean $useEditor])
Returns an HTML textarea field, along with its label and surrounding markup.

echo $Form->textarea_field('thingDescription', 'Description');

I'm trying to pass this:

echo $Form->textarea_field('courseDeets', 'Details',isset($details['courseDeets'])?$details['courseDeets']:false,"description",true);

The boolean useEditor parameter, which I've set to 'true', doesn't seem to be making a difference - any ideas?

Just looking to chase this issue a little, as I do need to deliver this to a client.

Thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to use a template to get all the options from the field types. Either that or manually add the editor through a UI plugin.

Hi Drew,

Thanks for the help.

How would I call a template in at that point? Here's my whole course.edit.post.php file:

<?php


    # Side panel
    echo $HTML->side_panel_start();
    echo $HTML->para('Add a new course here.');
    echo $HTML->side_panel_end();


    # Main panel
    echo $HTML->main_panel_start(); 
    include('_subnav.php');

    echo $HTML->heading1('Editing a Course');

    if ($message) echo $message;

    echo $HTML->heading2('Course details');


    echo $Form->form_start();

        echo $Form->text_field('courseTitle', 'Title',isset($details['courseTitle'])?$details['courseTitle']:false);
         if(is_object($Course)) {
            echo $Form->text_field('courseRef', 'Ref',isset($details['courseRef'])?$details['courseRef']:false);
            echo $Form->text_field('courseSlug', 'URL',isset($details['courseSlug'])?$details['courseSlug']:false);
            $Tag = new PerchXMLTag('<perch:shop id="courseDeets" type="textarea" editor="markitup" textile="true" html="true" />');
            echo $Form->textarea_field('courseDeets', 'Details',isset($details['courseDeets'])?$details['courseDeets']:false, null, $Tag);
            echo $Form->text_field('coursePrice', 'Price',isset($details['coursePrice'])?$details['coursePrice']:false);
        }
        echo $Form->hidden('courseID', isset($details['courseID'])?$details['courseID']:false);



        echo $Form->submit_field('btnSubmit', 'Save', $API->app_path().'/courses/');


    echo $Form->form_end();

    echo $HTML->main_panel_end();

?>

After the work done between us earlier in this thread, this section:

$Tag = new PerchXMLTag('<perch:shop id="courseDeets" type="textarea" editor="markitup" textile="true" html="true" />');
            echo $Form->textarea_field('courseDeets', 'Details',isset($details['courseDeets'])?$details['courseDeets']:false, null, $Tag);

is the bit that I need to be a WYSIWYG editor.

Could you let me know why this isn't working? I think I saw a call to get_fields_from_template somewhere in these files - would that be a resolution?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'd suggest looking at the sample app, because this has worked examples of how to do all these things. Particularly, look at modes/edit.pre.php and modes/edit.post.php.

A basic edit form would be:

echo $Form->form_start();
    echo $Form->fields_from_template($Template, $details, $Things->static_fields);
    echo $Form->submit_field('btnSubmit', 'Save', $API->app_path());
echo $Form->form_end();

This will build the form using proper field types based on the template in $Template.

Hi Drew,

Thanks for the help - I moved on to looking at the comments app.

I've found that the problem if I put the textile editor in is that it outputs the field as a dynamic field, whereas I need it as a static field.

I'll jump back onto this thread if I have any issues.

Hi Drew,

No real progress made, unfortunately!

The main issue seems now to be that I can't get the textarea field, 'courseDeets', to feed through as a static field. It keeps feeding through as a dynamic field, regardless of what I change.

Any ideas? Thanks!