2016-04-26 14 views
2

フィールドの属性を動的に設定しようとしています。 Joomlaのドキュメントは、私がすべてのフィールドを「必須」に設定したい場合、どのようにすればいいのでしょうか?ループ内のsetFieldAttribute

// works 
$this->form->setFieldAttribute('phone','required','required'); 

// not working 
$fields = $this->form->getFieldset('contact'); 
foreach ($fields as $field): 
$this->form->setFieldAttribute($field->name,'required','required'); // this cannot be done directly on a field? 
endforeach 

答えて

0

それは$フィールド - を思わ>名前が(「フォーム[電話]」の代わりに、単に「電話」のような)レンダリングされたフォームに入力フィールドに使用される名前を返します。あなたはのgetAttribute(「名前」)> $フィールド - を使用して名前を得ることができる必要があります:

// This should work :) 
$fields = $this->form->getFieldset(); 
foreach ($fields as $field): 
    $this->form->setFieldAttribute($field->getAttribute('name'),'required','required'); 
endforeach; 

私はあなたがメソッドのsetAttribute(キー、ヴァル)を期待する、これは最も明白な方法ではありません同意しますフィールドオブジェクトに...