Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JForm::findField rename $element loop variable #9435

Closed
dr138 opened this issue Mar 15, 2016 · 2 comments
Closed

JForm::findField rename $element loop variable #9435

dr138 opened this issue Mar 15, 2016 · 2 comments

Comments

@dr138
Copy link
Contributor

dr138 commented Mar 15, 2016

Steps to reproduce the issue

The

foreach ($elements as $element)
{
...
}

loop within findField should have the loop variable renamed to (eg) $el, otherwise it can end up being returned as the function return value.

Eg for

$jform = new JForm('testform');
$jform->load(<<<'XML'
<form>
  <fields name="A">
    <field name="fielda"/>
    <fields name="B">
      <field name="fieldab"/>
    </fields>
  </fields>
</form>
XML
);
$field = $jform->findField('fieldab','A'); // should return false, but returns whole <fields name="A"> element.
print ($field? $field->asXML()."\n": "false")."\n";

And then for

$jform->load(<<<'XML'
<form>
<fields name="A">
  <field name="fieldab"/>
</fields>
</form>
XML
,true); // should add a new <field name="fieldab"/> element to the <fields name="A"> element, instead deletes the whole original <fields name="A"> element and adds the <field> at the "top" level.
print $jform->getxml()->asXML();

David

Expected result

See commented code above

Actual result

See commented code above

System information (as much as possible)

Additional comments

@izharaazmi
Copy link
Contributor

I confirm this issue exists.

But...., the given code won't execute from outside JForm as findField is a protected method. Using getField will still return false because field setup fails at libraries/joomla/form/form.php:1823 as libraries/joomla/form/field.php:557 returns false.

@dr138 Please send a PR.

@brianteeman
Copy link
Contributor

Closed as we have a PR #11732

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants