Valery Posted December 4, 2013 Share Posted December 4, 2013 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! Link to comment Share on other sites More sharing options...
Soma Posted December 4, 2013 Share Posted December 4, 2013 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 1 Link to comment Share on other sites More sharing options...
Valery Posted December 5, 2013 Author Share Posted December 5, 2013 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); Link to comment Share on other sites More sharing options...
Soma Posted December 5, 2013 Share Posted December 5, 2013 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(); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now