Jump to content

Recommended Posts

Posted

Hi guys,

I've been trying to play with $field->getInputfield() to get my PW field data displayed as part of a form. 

$category = $fields->get('related');

$field = $category->getInputfield($page);

echo $field->render();
 
 
'related' is a Page field configured to be displayed as Radios ("Input Field Type" = Radios).
 
The question is, how do I access this Inputfield's values before rendering the output? I did var_dump on it and here is what it gave me:
 
object(InputfieldPage)#272 (12) {
  ["inputfieldWidget":protected]=>
  object(InputfieldRadios)#284 (11) {
    ["options":protected]=>
    array(7) {
      [1277]=>
      int(1277)
      [1280]=>
      int(1280)
      [1281]=>
      int(1281)
      [1282]=>
      int(1282)
      [1283]=>
      int(1283)
      [1284]=>
      int(1284)
      [1394]=>
      int(1394)
    }
    ["optionAttributes":protected]=>
    array(0) {
    }
 

I need to edit the options before rendering the Radios field but how would I go about doing it?

Please help!

Posted

You have the value already with the $page->related or not?

$inputfield = $category->getInputfield($page);
$inputfield->attr("value", $page->related);
...

This way you populate the inputfield 

  • Like 1
Posted

Thanks, Soma!

I'd just add that the following selects an option in the radio button list:

$labelFieldName = fields->get("related")->labelFieldName;
$inputfield->setAttribute('value', $page->$labelFieldName);
 
Posted

Thanks, Soma!

I'd just add that the following selects an option in the radio button list:

$labelFieldName = fields->get("related")->labelFieldName;
$inputfield->setAttribute('value', $page->$labelFieldName);
 

Looks a little uneccessary complicated.

I'm not sure I understand your code and what is "labelFieldName"? You already got the field name "related", which has nothing to do with the label of the field.

You can also just use attr(key,value) instead of setAttribute(key, value)

To recap you opening example:

$category = $fields->get('related');
$field = $category->getInputfield($page);
$field->attr("value",$page->related);
echo $field->render();
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...