Forum

Thread tagged as: Question, Problem, Forms

Form not submitting—nesting problem?

Hi all,

I have a problem with a Perch form not being submitted—on some pages, that is.

The backstory:
On a website I have a callback form being displayed on several pages. The form is embedded in different ways, as the pages need to fulfill different requirements.
For some pages the form is embedded inside the template _actions.html using

<perch:template path="content/_callbackform.html" />  

That's, because it only needs to display, when some condition in _actions.html is met.
The form is submitting perfectly, where _actions.html is embedded in the page's PHP like so

<?php
    perch_content_custom('Content',array(
        'template'=>'_action.html'
    ));
?>

When, however, _actions.html is embedded in another Perch template with

<perch:template path="content/_action.html" />

it is displaying perfectly, but won't send.
After clicking "submit" the page is reloaded with the form showing the values filled in before—not with the success message—and no data is sent. Neither to the database, nor to the e-mail address associated with that form.

What am I missing here?
Is it not possible to nest templates in that depth, maybe?

Nils Mielke

Nils Mielke 3 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version of Perch are you using?

That would be Perch 2.6.3

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try with the current version? I thought we'd fixed this.

Oh, okay. Will try and report.

Unfortunately the update didn't fix the problem. Still the form returns as described above—without submitting.

Interestingly, the fields with the attribute "required=false" were being marked as required by Firefox when trying to send. That didn't happen before the update, but could be fixed by removing that attribute altogether.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's right - required is one of those weird boolean attributes in HTML that is either present or not. Setting it to false doesn't help.

Yeah, weird it is.
Any ideas on how to fix the form, though?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that should work. Can you show me the debug output once the form is posted?

Time Δ Debug Message
-1,3503 0 SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
-1,3446 0,0057 Using sub-template: /templates/content/_action.html
-1,3445 0,0001 Using sub-template: /templates/content/_careeritem.html
-1,3444 0,0001 Using sub-template: /templates/content/_publications.html
-1,3443 0,0001 Using sub-template: /templates/content/_trainingitems.html
-1,3442 0,0001 Using sub-template: /templates/content/_research.html
-1,344 0,0001 Using sub-template: /templates/content/_texttriplecol.html
-1,3439 0,0001 Using sub-template: /templates/content/_textdoublecol.html
-1,3438 0,0001 Using sub-template: /templates/content/_links.html
-1,3436 0,0001 Using sub-template: /templates/content/_textcol1.html
-1,3435 0,0002 Using sub-template: /templates/content/_documents.html
-1,3434 0,0001 Using sub-template: /templates/content/_textcol2.html
-1,3433 0,0001 Using sub-template: /templates/content/_textcol3.html
-1,3389 0,0043
Array
(
[date] => required
[email] => required
[company] => required
[department] => required
[billing] => required
[VAT] => required
[privacypolicy] => required
[terms] => required
[event] => required
[name2] => required
[email2] => required
[company2] => required
[department2] => required
[phone2] => required
)
-1,3293 0,0097 SELECT * FROM perch2_pages WHERE pagePath='/de/unternehmen/training/index.php' LIMIT 1
-1,329 0,0003 Using template: /templates/pages/attributes/seo.html
-1,328 0,001 SELECT * FROM perch2_pages WHERE pagePath='/de/unternehmen/training/index.php' LIMIT 1
-1,32 0,008 Compiling SASS file: /assets/sass/styles.scss
-0,2486 1,0714 Compiling SASS file: /assets/sass/ie9.scss
-0,2465 0,0021 Compiling SASS file: /assets/sass/nomediaqueries.scss
0,5293 0,7758 Compiling SASS file: /assets/sass/ie8.scss
0,5411 0,0118 SELECT groupID FROM perch2_navigation WHERE groupSlug='main-de' LIMIT 1
0,5413 0,0002 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=7 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
0,5415 0,0002 SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=7 AND p.pagePath='/de/unternehmen/training/index.php' LIMIT 1
0,5416 0,0001 SELECT pageID FROM perch2_navigation_pages WHERE groupID=7 AND pageTreePosition IN ('000-004-013', '000-004', '000')
0,5418 0,0002 Using template: /templates/navigation/item.html
0,5445 0,0026 SELECT groupID FROM perch2_navigation WHERE groupSlug='contact-de' LIMIT 1
0,5446 0,0001 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=9 AND p.pageNew=0 ORDER BY np.pageTreePosition ASC
0,5447 0,0001 SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=9 AND p.pagePath='/de/unternehmen/training/index.php' LIMIT 1
0,5448 0,0001 Using template: /templates/navigation/contact.html
0,5454 0,0006 Using template: /templates/search/search-form-de.html
0,5466 0,0012 SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/de/unternehmen/training/index.php' OR regionPage='*' ORDER BY regionPage DESC
0,5468 0,0002 SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Content' AND (regionPage='/de/unternehmen/training/index.php' OR regionPage='*')
0,547 0,0001 SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=70 AND idx.itemRev=20)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
0,5472 0,0002 Using template: /templates/content/_output1.html
0,5474 0,0002 Using sub-template: /templates/content/_quote.html
0,5493 0,002 SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/de/unternehmen' OR pageSortPath='/de/unternehmen' LIMIT 1
0,5495 0,0001 SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-001-003%' AND pageDepth >=2 AND pageDepth<=5 ORDER BY pageTreePosition ASC
0,5498 0,0003 SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/de/unternehmen/training/index.php' LIMIT 1
0,5499 0,0001 SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-001-003-005', '000-001-003', '000-001', '000')
0,5503 0,0004 Using template: /templates/navigation/item.html
0,5576 0,0073 SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=70 AND idx.itemRev=20)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
0,5578 0,0002 Using template: /templates/content/_output2.html
0,558 0,0002 Using sub-template: /templates/content/_action.html
0,5581 0,0001 Using sub-template: /templates/content/_careeritem.html
0,5582 0,0001 Using sub-template: /templates/content/_publications.html
0,5583 0,0001 Using sub-template: /templates/content/_trainingitems.html
0,5585 0,0002 Using sub-template: /templates/content/_research.html
0,5586 0,0002 Using sub-template: /templates/content/_texttriplecol.html
0,5587 0,0001 Using sub-template: /templates/content/_textdoublecol.html
0,5588 0,0001 Using sub-template: /templates/content/_links.html
0,559 0,0001 Using sub-template: /templates/content/_textcol1.html
0,5591 0,0001 Using sub-template: /templates/content/_documents.html
0,5592 0,0001 Using sub-template: /templates/content/_textcol2.html
0,5593 0,0001 Using sub-template: /templates/content/_textcol3.html
0,5601 0,0007 Using sub-template: /templates/content/_callbackform.html
0,5921 0,032 SELECT groupID FROM perch2_navigation WHERE groupSlug='contact-de' LIMIT 1
0,5922 0,0002 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=9 AND p.pageNew=0 ORDER BY np.pageTreePosition ASC
0,5924 0,0002 SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=9 AND p.pagePath='/de/unternehmen/training/index.php' LIMIT 1
0,5925 0,0001 Using template: /templates/navigation/contact.html
0,5932 0,0006 Using template: /templates/search/search-form-de.html
0,5942 0,001 SELECT groupID FROM perch2_navigation WHERE groupSlug='footer-de' LIMIT 1
0,5943 0,0001 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=8 AND p.pageNew=0 ORDER BY np.pageTreePosition ASC
0,5944 0,0002 SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=8 AND p.pagePath='/de/unternehmen/training/index.php' LIMIT 1
0,5946 0,0002 Using template: /templates/navigation/item.html
0,5966 0,002
Array
(
[type] => 8
[message] => Undefined index: training
[file] => /is/htdocs/wp10638308_T9CU9PHW0N/www/webspace[…]/templates/layouts/global.header.php
[line] => 24
)

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's a lot of sub templates! Which is the form in?

True. But they are not all used on that one page. Perch decides which one to use depending on condition determined by the content.

The form is in sub-template: /templates/content/_callbackform.html
which is loaded into sub-template: /templates/content/_action.html
which is loaded into template: /templates/content/_output2.html
which is called in PHP.

In this case it is only displayed, when some condition in /templates/content/_action.html is met.
That's why it is so nested.
On other pages /templates/content/_callbackform.html is called in PHP directly.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think sub templates are recursively loaded by the form handler, by the look of it.

Too bad.
Well, I went through all the clients pages to handle that differently and now it all seems to work.
Thanks for your quick replies and your endurance, Drew. :)