cst989 Posted December 17, 2019 Share Posted December 17, 2019 Hi all, I have a simple issue with inputfield:attr() not setting a value. I'm doing this in ready.php $forms->addHook('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name != 'enquiry_form') return; $inputfield = $form->getChildByName('cart'); if($inputfield) { $cart = json_encode(wire('session')->get('cart')); $inputfield->attr('value', $cart); } }); This is lifted straight from formbuilder hooks and inputfield method specs. If I echo $cart it's definitely a simple string of json, but nothing appears in the cart field (which is a plain text field - later to change to hidden) Is there something obvious I might've overlooked here? As a side question, can anyone think of a better way to do this - add my cart to a Formbuilder submission (it's not a shop, just an enquiry) - while still storing entries easily in the formbuilder entries list. Link to comment Share on other sites More sharing options...
gebeer Posted December 18, 2019 Share Posted December 18, 2019 I think you need to return the modified argument $forms->addHook('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name != 'enquiry_form') return; $inputfield = $form->getChildByName('cart'); if($inputfield) { $cart = json_encode(wire('session')->get('cart')); $inputfield->attr('value', $cart); // you can try var_dump($inputfield->attr('value') here to see if the value was set } $e->arguments(0, $form); // this will return the modified form object to the hooked method }); 1 Link to comment Share on other sites More sharing options...
cst989 Posted December 18, 2019 Author Share Posted December 18, 2019 Var dump returns a string but still nothing in the field... It's occurring to me now, maybe I'm misunderstanding this whole thing? Is this actually meant to be populating the html field itself? Will this still work if I'm using embed method C or D on Formbuilder? I'm trying to avoid populating this with javascript but that would be so much easier... perhaps I'll just abandon it. Link to comment Share on other sites More sharing options...
gebeer Posted December 19, 2019 Share Posted December 19, 2019 Sorry, that was the only thing I figured could be wrong. Maybe someone else can jump in? 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