Forum

Thread tagged as: Problem, Error, Forms

Required validation fails when using

Hi,

On a client's site in development there are two identical forms that require different IDs. To prevent duplicate code I have split the fields into a separate partial template however the required="true" no longer works when submitting the form allowing me to enter blank inputs.

Am I attempting to push through too much dynamic content through the perch:template tags?

Diagnostics:

Perch: 2.8.31
Production mode: Development (10)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_forms (1.8.3), jw_locator (1.1.1), jw_translations (1)
DB driver: PDO
DB tables: perch2_blog_authors (1), perch2_blog_comments (0), perch2_blog_index (1748), perch2_blog_posts (76), perch2_blog_posts_to_tags (0), perch2_blog_sections (1), perch2_blog_tags (0), perch2_blogs (1), perch2_categories (0), perch2_category_counts (0), perch2_category_sets (2), perch2_content_index (7725), perch2_content_items (646), perch2_content_regions (180), perch2_forms (1), perch2_forms_responses (6), perch2_jw_locator_failed_jobs (0), perch2_jw_locator_locations (2), perch2_jw_locator_markers (2), perch2_navigation (1), perch2_navigation_pages (11), perch2_page_templates (21), perch2_pages (63), perch2_resource_log (853), perch2_resource_tags (5), perch2_resources (394), perch2_resources_to_tags (28), perch2_scheduled_tasks (2), perch2_settings (27), perch2_user_passwords (1), perch2_user_privileges (44), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
$apps_list = [
    'content',
    'categories',
    'perch_blog',
    'perch_forms',
    'jw_translations',
    'jw_locator'
];
Scheduled tasks for jw_locator: geocode_location_batch (10 mins)
Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
Editor plug-ins: markitup, redactor
H1: 07834988bfee709b2937769f947bf55d
L1: c5835d8fb375147b3ac426c4c2e79904
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #4A96D2
content_singlePageEdit: 1
siteURL: /
hideBranding: 1
content_collapseList: 1
lang: en-gb
update_2.8.30: done
latest_version: 2.8.15
on_sale_version: 2.8.31
headerScheme: dark
dashboard: 1
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
logoPath: /admin/resources/ts-logo2x.png
helpURL: mailto:design@rootstudio.co.uk
perch_blog_update: 5.0.1
perch_blog_post_url: /news/{postSlug}
jw_locator_batch_size: 100
perch_blog_site_name:
perch_blog_slug_format: {postID}-{postTitle}
perch_blog_akismet_key:
perch_blog_max_spam_days: 0
perch_blog_comment_notify: 0
jw_locator_google_api_key: XXXXXXXXX
update_2.8.31: done
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_TZ: UTC
PERCH_EMAIL_FROM: james@rootstudio.co.uk
PERCH_EMAIL_FROM_NAME: Root Studio
PERCH_LOGINPATH: /admin
PERCH_PATH: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin
PERCH_CORE: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin/core
PERCH_RESFILEPATH: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin/resources
PERCH_RESPATH: /admin/resources
PERCH_HTML5: 1
PERCH_SCHEDULE_SECRET: bAmrLFCGYkG27HwpvmMfiRrktZRoctwJ
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: total_perch
PERCH_DB_PREFIX: perch2_
PERCH_DEBUG: 1
PERCH_PRODUCTION_MODE: 10
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: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
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
HOSTING SETTINGS

PHP: 5.6.10
Zend: 2.6.0
OS: Darwin
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
MySQL server: 5.5.42
Free disk space: 375.59 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, intl, json, ldap, mbstring, session, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, readline, Reflection, mysql, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, cgi-fcgi, imap, gettext, mcrypt, yaz, pgsql, pdo_pgsql, xdebug
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
PHP_FCGI_CHILDREN: 4
PWD: /Applications/MAMP/fcgi-bin
PHP_FCGI_MAX_REQUESTS: 200
__CF_USER_TEXT_ENCODING: 0x1F5:0x0:0x0
ORIG_SCRIPT_NAME: /fcgi-bin/php5.6.10.fcgi
ORIG_PATH_TRANSLATED: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin/core/settings/diagnostics/index.php
ORIG_PATH_INFO: /admin/core/settings/diagnostics/index.php
ORIG_SCRIPT_FILENAME: /Applications/MAMP/fcgi-bin/php5.6.10.fcgi
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
REQUEST_URI: /admin/core/settings/diagnostics/?extended
QUERY_STRING: extended
REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.1
GATEWAY_INTERFACE: CGI/1.1
REDIRECT_URL: /admin/core/settings/diagnostics/index.php
REDIRECT_QUERY_STRING: extended
REMOTE_PORT: 65480
SCRIPT_FILENAME: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build/admin/core/settings/diagnostics/index.php
SERVER_ADMIN: you@example.com
DOCUMENT_ROOT: /Users/James/Repositories/New Chapter Marketing/total-sweet-uk/build
REMOTE_ADDR: ::1
SERVER_PORT: 80
SERVER_ADDR: ::1
SERVER_NAME: totalsweet.local
SERVER_SOFTWARE: Apache
PATH: /usr/bin:/bin:/usr/sbin:/sbin
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://totalsweet.local/admin/core/settings/diagnostics/
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17
HTTP_COOKIE: _ga=GA1.2.2069913369.1466584981; _gat=1; PHPSESSID=82d612fb3a9060ff9c58a8e62090a379; cmsa=1
HTTP_CONNECTION: keep-alive
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_HOST: totalsweet.local
REDIRECT_STATUS: 200
REDIRECT_HANDLER: php-fastcgi
FCGI_ROLE: RESPONDER
PHP_SELF: /admin/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1470384861.74
REQUEST_TIME: 1470384861
argc: 1

Form master template:

<perch:form class="o-weighted__priority form" app="perch_forms" id="recipe_booklet">
    <perch:template path="_booklet_fields.html" />
</perch:form>

Fields template:

<perch:content id="form_title" type="text" label="Title" size="xl" title="true" required="true" suppress="true" />
<perch:content id="form_lead" type="textarea" label="Lead" size="xs" suppress="true" />
<perch:content id="form_body" type="textarea" label="Content" html="true" editor="redactor" suppress="true" divider-after="Post-Submission" />

<header class="header-basic">
    <h1 class="header-basic__title +alt">
        <perch:content id="form_title" />
    </h1>
</header>

<div class="rich-text">
    <perch:if exists="form_lead">
        <p class="lead +alt">
            <perch:content id="form_lead" type="textarea" />
        </p>
    </perch:if>

    <perch:content id="form_body" html="true" />

    <div class="o-inset">
        <div class="form__row">
            <div class="form-field">
                <perch:label for="name" class="form-field__label">Name</perch:label>
                <div class="form-field__control">
                    <perch:input id="name" type="text" class="text-field text-field--lg" required="true" label="Name" />
                </div>

                <perch:error for="name" type="required">
                    <span class="form-field__message form-field__message--error">
                        Please add your name.
                    </span>
                </perch:error>
            </div>
        </div>
        <div class="form__row">
            <div class="form-field">
                <perch:label for="email" class="form-field__label">Email</perch:label>
                <div class="form-field__control">
                    <perch:input id="email" type="email" class="text-field text-field--lg" required="true" label="Email" />
                </div>

                <perch:error for="email" type="required">
                    <span class="form-field__message form-field__message--error">
                        Please add your email address.
                    </span>
                </perch:error>

                <perch:error for="email" type="format">
                    <span class="form-field__message form-field__message--error">
                        Please check your email address is correct.
                    </span>
                </perch:error>
            </div>
        </div>
        <div class="form__row">
            <div class="form-field">
                <perch:label for="marketing" class="toggle ">
                    Please tick this box if you don’t want to receive news on further promotions and offers
                    from us (either way we will never pass your details on to a third party).
                    <perch:input id="marketing" type="checkbox" value="NO MARKETING" label="Marketing" />
                </perch:label>
            </div>
        </div>
        <div class="form__row">
            <div class="form-field">
                <perch:input type="submit" class="button button--sm" value="Submit" />
            </div>
        </div>
    </div>
</div>

<perch:success>
    <perch:content id="thanks_title" type="text" label="Thanks Title" size="xl" title="true" required="true" suppress="true" />
    <perch:content id="thanks_body" type="textarea" label="Thanks Message" html="true" editor="redactor" suppress="true" />

    <div class="o-weighted__priority">
        <header class="header-basic">
            <h1 class="header-basic__title">
                <perch:content id="thanks_title" />
            </h1>
        </header>
        <div class="rich-text">
            <perch:content id="thanks_body" html="true" />
        </div>
    </div>
</perch:success>
James Wigger

James Wigger 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That certainly looks like it should work. If you turn debug on for the page and then submit the form, do you see any errors?

It looks like it cannot find the template if a relative path is used on form submission, though the fields will appear in the admin panel and render correctly on page.


Time Δ Debug Message 0.0306 0 [26] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0 0.0428 0.0122 Requested sub-template not found: /_booklet_fields.html 0.0445 0.0016 [1] SELECT * FROM perch2_forms WHERE formKey='recipe_booklet' LIMIT 1 0.0485 0.0041 [1] SELECT * FROM perch2_pages WHERE pagePath='/recipes/recipe-booklet.php' LIMIT 1 0.0504 0.0019 INSERT INTO perch2_forms_responses(responseJSON,formID,responseIP,responseSpamData) VALUES('{\"fields\":[],\"files\":[],\"page\":{\"id\":\"12\",\"title\":\"Recipe Booklet\",\"path\":\"\\/recipes\\/recipe-booklet.php\",\"navtext\":\"Recipe Booklet\"}}','1','::1','{\"fields\":[],\"environment\":{\"PHP_FCGI_CHILDREN\":\"4\",\"PWD\":\"\\/Applications\\/MAMP\\/fcgi-bin\",\"SHLVL\":\"0\",\"PHP_FCGI_MAX_REQUESTS\":\"200\",\"__CF_USER_TEXT_ENCODING\":\"0x1F5:0x0:0x0\",\"ORIG_SCRIPT_NAME\":\"\\/fcgi-bin\\/php5.6.10.fcgi\",\"ORIG_PATH_TRANSLATED\":\"\\/Users\\/James\\/Repositories\\/New Chapter Marketing\\/total-sweet-uk\\/build\\/recipes\\/recipe-booklet.php\",\"ORIG_PATH_INFO\":\"\\/recipes\\/recipe-booklet.php\",\"ORIG_SCRIPT_FILENAME\":\"\\/Applications\\/MAMP\\/fcgi-bin\\/php5.6.10.fcgi\",\"SCRIPT_NAME\":\"\\/recipes\\/recipe-booklet.php\",\"REQUEST_URI\":\"\\/recipes\\/recipe-booklet.php\",\"QUERY_STRING\":\"\",\"REQUEST_METHOD\":\"POST\",\"SERVER_PROTOCOL\":\"HTTP\\/1.1\",\"GATEWAY_INTERFACE\":\"CGI\\/1.1\",\"REDIRECT_URL\":\"\\/recipes\\/recipe-booklet.php\",\"REMOTE_PORT\":\"53988\",\"SCRIPT_FILENAME\":\"\\/Users\\/James\\/Repositories\\/New Chapter Marketing\\/total-sweet-uk\\/build\\/recipes\\/recipe-booklet.php\",\"SERVER_ADMIN\":\"you@example.com\",\"DOCUMENT_ROOT\":\"\\/Users\\/James\\/Repositories\\/New Chapter Marketing\\/total-sweet-uk\\/build\",\"REMOTE_ADDR\":\"::1\",\"SERVER_PORT\":\"80\",\"SERVER_ADDR\":\"::1\",\"SERVER_NAME\":\"totalsweet.local\",\"SERVER_SOFTWARE\":\"Apache\",\"SERVER_SIGNATURE\":\"\",\"PATH\":\"\\/usr\\/bin:\\/bin:\\/usr\\/sbin:\\/sbin\",\"HTTP_ACCEPT_ENCODING\":\"gzip, deflate\",\"HTTP_ACCEPT_LANGUAGE\":\"en-us\",\"HTTP_REFERER\":\"https:\\/\\/totalsweet.local\\/recipes\\/recipe-booklet.php\",\"HTTP_USER_AGENT\":\"Mozilla\\/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit\\/601.5.17 (KHTML, like Gecko) Version\\/9.1 Safari\\/601.5.17\",\"HTTP_ACCEPT\":\"text\\/html,application\\/xhtml+xml,application\\/xml;q=0.9,*\\/*;q=0.8\",\"HTTP_CONNECTION\":\"keep-alive\",\"CONTENT_LENGTH\":\"138\",\"HTTP_COOKIE\":\"_ga=GA1.2.2069913369.1466584981; _gat=1; PHPSESSID=83aac21a9a350df08fc242ec525a4c82; cmsa=1\",\"HTTP_ORIGIN\":\"https:\\/\\/totalsweet.local\",\"CONTENT_TYPE\":\"application\\/x-www-form-urlencoded\",\"HTTP_HOST\":\"totalsweet.local\",\"REDIRECT_STATUS\":\"200\",\"REDIRECT_HANDLER\":\"php-fastcgi\",\"FCGI_ROLE\":\"RESPONDER\",\"PHP_SELF\":\"\\/recipes\\/recipe-booklet.php\",\"REQUEST_TIME_FLOAT\":1470400218.43,\"REQUEST_TIME\":1470400218,\"argv\":[],\"argc\":0}}') 0.0507 0.0003 [1] SELECT * FROM perch2_forms_responses WHERE responseID='8' LIMIT 1 0.0514 0.0007 No ids to log.

Setting the template to:

<perch:form class="o-weighted__priority form" app="perch_forms" id="recipe_booklet">
    <perch:template path="content/forms/_booklet_fields.html" />
</perch:form>

does work as expected.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Great.

The path is relative to the perch/templates directory.

https://docs.grabaperch.com/docs/templates/includes/