Problem/Motivation

Currently views forms are doubling up on the form tag.

Steps to reproduce:

  1. Visit /admin/content
  2. View Source

Proposed resolution

Determine where this got in, and remove duplicate.

Remaining tasks

User interface changes

API changes

Data model changes

Files: 
CommentFileSizeAuthor
#12 Test_result___Site-Install.png121.6 KBjoelpittet
#10 nested_form_tag_in-2558061-10.patch2.5 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 113,987 pass(es). View
#10 nested_form_tag_in-2558061-10-tests-only.patch1.2 KBjoelpittet
FAILED: [[SimpleTest]]: [PHP 5.5 MySQL] 110,398 pass(es), 5 fail(s), and 0 exception(s). View
#8 Source_of__http___d8_dev_admin_content.png42.09 KBjoelpittet
#7 nested_form_tag_in-2558061-7.patch657 byteslauriii
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 110,399 pass(es). View
#2 nested_form_tag_in-2558061-2.patch1.3 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 109,991 pass(es). View
Source_of__http___d8_dev_admin_content.png48.25 KBjoelpittet

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
Issue tags: +Needs manual testing
FileSize
1.3 KB
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 109,991 pass(es). View

Well this seems to work because it is already a form, and #theme => form is a #theme_wrapper for
#type => form
by default. Not totally sure about the removal of the #children thing in the preprocess but feels right. Needs manual testing for sure.

Aki Tendo’s picture

Status: Needs review » Reviewed & tested by the community

Tested. Redundant tag did disappear after patch was applied.

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

its a bug, so we should have tests, sorry.

joelpittet’s picture

Issue tags: -Needs manual testing

No need to apologize, you are right it does:) It's just a chore sometimes when bugs are easy to fix. And if you see my tests you'd regret asking for them, muahaha:D

I've got the assertion ready. Just need to build a view like admin/content that has the nested form.

    // Ensure we don't have nested form elements.
    $xpath = $this->xpath('//form//form');
    $this->assertFalse($xpath, 'The views form element is not nested.');

There doesn't seem to be any Views Form Tests in core. May consider creating a new one ViewsFormTest

joelpittet’s picture

lauriii’s picture

Status: Needs work » Needs review
FileSize
657 bytes
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 110,399 pass(es). View

I cant manually reproduce this anymore. Neither do my tests :)

joelpittet’s picture

Maybe the type of form is wrong, I can still preproduce this by view source on the admin/content page.

joelpittet’s picture

Assigned: Unassigned » joelpittet

Also that test is incorrect, if you look at that output it doesn't really create one. But @dawehner let me know "Bulk Update" test may work so I'm going to try that.

joelpittet’s picture

Assigned: joelpittet » Unassigned
Issue tags: -Needs tests
FileSize
1.2 KB
FAILED: [[SimpleTest]]: [PHP 5.5 MySQL] 110,398 pass(es), 5 fail(s), and 0 exception(s). View
2.5 KB
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 113,987 pass(es). View

Apparently my xpath() is crap or it just sucks at finding nested form tags... wrote a regex instead.

The last submitted patch, 10: nested_form_tag_in-2558061-10-tests-only.patch, failed testing.

joelpittet’s picture

Issue summary: View changes
FileSize
121.6 KB

For the doubters of the xpath not working.

    $elements = $this->xpath('//form//form');
    $this->assertFalse($elements, 'Xpath no nested forms.');

the xpath could be wrong... but I wanted to find also /form/div/form

joelpittet’s picture

Title: Nested form tag in views forms. » Nested form tag in views forms
Issue tags: +Quick fix
xjm’s picture

Can we confirm when/how/why the children rendering was added in the first place? To make sure we're not fixing one usecase to break another or something.

cweagans’s picture

+    $result = (bool) preg_match('#]*?>(?!/form).*getRawContent());

Is there a reason to use a regex over a real HTML parser here? There's an HTML5-aware one in the masterminds/html5 package that's already in core. This would be a great place to use it.

joelpittet’s picture

Assigned: Unassigned » joelpittet
Status: Needs review » Needs work

@cweagans thanks for the suggestion, didn't think to use that package, will give it a try. see #12 and #10 for why regex was used, because xpath didn't work as expected and I wanted to get something working and use something I know. But I'll give that package a try.

@xjm I know we want to remove it as it's one of the remaining "why is this being used" legacy function calls, and removing it helped resolve the problem.

  1. It helped cause this issue it seemed: #2119881: views BulkFormBase shows 'Apply' button twice
  2. And apparently I helped move it from the theme function here #1912600: Remove theme_views_form_views_form in favour of a prerender callback.
  3. And it originally came from the theme function when views was added to core a626abb - Add the 7.x-3.x Views branch. (2012-10-07 17:51:56 -0400)<merlinofchaos>
function theme_views_form_views_form($variables) {
...
  // Render and add remaining form fields.
  return drupal_render_children($form);
}

And we've removed all the other instance of that in core, so I think it's safe to remove.

joelpittet’s picture

Status: Needs work » Needs review

@cweagans Good news: Mastermind/html5 does a better job creating the DOMDocument for HTML5 and ignores errors(where SimpleTest just suppresses errors).
This means I can traverse the DOMDocument it creates much better than the one that SimpleTest creates. And I could test this problem with this:

$html5 = new HTML5();
$dom = $html5->loadHTML($html);
$form_list = $dom->getElementsByTagName('form');
foreach ($form_list as $node) {
  $nested_form_list = $node->getElementsByTagName('form');
  if ($nested_form_list->length) {
    print "Found nested form: " . $nested_form_list->item(0)->getAttribute('id') . "\n";
    break;
  }
}

Bad news: XPath doesn't work with HTML5, so the DOMXPath() basically finds nothing. Seems to be documented in this issue: https://github.com/Masterminds/html5-php/issues/12

HTML5 doesn't support them the way XML does.

To see the work I did around this try it out for your self, maybe I made a mistake(very likely):
https://gist.github.com/joelpittet/62e7e5bd83e793c599c2

Output: php < index.php


--------------------
WebTestBase
--------------------
Forms by tag name: 3
Form: form-1

Form: form-2
1
Form: form-3
1
Simple XML traverse: 0
//div//div: 1
//form: 3
//form//form: 0
//form/form: 0
--------------------
MasterMind\HTML5
--------------------
Forms by tag name: 3
Form: form-1
1
Found nested form: form-2
//div/div: 0
//form: 0
//form//form: 0
//form/form: 0
Simple XML traverse: 1
//div//div: 0
//form: 0
//form//form: 0
//form/form: 0
--------------------
Error Handler
--------------------
Caught error: Unexpected end tag : form in Entity, line: 10

So with that, I'm going to stick with my simple regex because it's still more to the point and straight forward to read than loading the external library just to manually traverse, IMO.

cweagans’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for looking into that. Given that going another route is so much extra code, I think the regex makes sense.

Aki Tendo’s picture

Yeah, for now I think this will have to do. Long term we need to find a different solution from XPath because HTML is not XHTML, there are many subtle differences. Browsers ignore them smoothly, but validators don't. One large examples - in HTML the /> ending on single tags is invalid, in XML and XHTML it's required. A prime example:
<br> vs. <br />

There's now an HTML 5 extension for Tidy, but the vast majority of libraries out there don't have tidy installed - those that do usually have the old html 4 version. Installing tidy is not trivial (unless you're using a virtual machine) so despite its power it's probably not usable with Drupal.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: nested_form_tag_in-2558061-10.patch, failed testing.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community

Looks like a random failure. I applied to patch and ran "Drupal\user\Tests\UserPasswordResetTest" locally and it passed.

joelpittet’s picture

Assigned: joelpittet » Unassigned

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: nested_form_tag_in-2558061-10.patch, failed testing.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a7a9e36 and pushed to 8.0.x. Thanks!

  • alexpott committed a7a9e36 on 8.0.x
    Issue #2558061 by joelpittet, lauriii: Nested form tag in views forms
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.