Manol Posted October 10, 2013 Share Posted October 10, 2013 Anybody knows how to add a hook directly in the template or a link in this forum with some example? Thank you. Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 I´m trying the following in my template function hookEmail($event){ $file = $event->return; echo "value: ". $file->value; } $form = $forms->get("reconocimientos"); echo $form->render(); $form->get("reconocimientos")->addHookAfter("processInput", null, 'hookEmail'); but get this error Error: Call to a member function addHookAfter() on a non-object (line ... Link to comment Share on other sites More sharing options...
adrian Posted October 10, 2013 Share Posted October 10, 2013 I think your issue is not the hook, but rather the: $form->get("reconocimientos") It is not an object. I am not really very familiar with hooking in templates, but I just tested this and it works: <?php $page->addHookBefore('Page::loaded', null, 'errorTest'); function errorTest(HookEvent $e) { error_log('testhook'); } so I think you are on the right track, but you need to sort out your form object. Are you maybe using FormBuilder? or do you have $forms defined elsewhere in your code? Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 Hello Adrian. You're right I'm using formbuilder and including it with option C, do you know the difference? Thank you Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2013 Share Posted October 10, 2013 maybe try something like this? to get the field it sometimes easiest to use a find() or maybe simply $field = $form->get("name=reconocimientos"); function hookEmail($event){ $file = $event->return; echo "value: ". $file->value; } $form = $forms->get("reconocimientos"); $field = $form->find("name=reconocimientos")->first(); echo "field: " . $field->name . "<br/>"; $field->addHookAfter("processInput", null, 'hookEmail'); echo $form->render(); the hook needs to be before you render the form too. but not sure what you want to achieve 2 Link to comment Share on other sites More sharing options...
adrian Posted October 10, 2013 Share Posted October 10, 2013 Sorry Manol - I don't have formbuilder, so I really don't know how it works, but maybe this post from Soma might help: http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/?p=30979 EDIT: Speaking of the man himself 1 Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2013 Share Posted October 10, 2013 Sorry Manol - I don't have formbuilder, so I really don't know how it works, but maybe this post from Soma might help: http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/?p=30979 EDIT: Speaking of the man himself Thanks adrian, I have a feeeling I'm repeating myself over and over Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 NOTE: I'm really sorry but sometimes is really hard to find the right information in the forum, I try hard to found it before making people losing time, and is not a complain at all, people here is in generaly very keen on helping others as I do when I have the knowledge. Special thanks to Soma, he really has helped me a lot and still does. Anyway, what I'm trying is to hook a formbuilder form embedded with option C, I would like to copy some files and data from the form to an external database and I need to hook the form after submit to get the results but I'm totally unable to do that, even the above code is not working for me, I thought I had understood how it works and even make a little resume to help others here but no way to do it after hours researching, I know I'm near the solution but no way to get it work. Any help is welcome. 1 Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2013 Share Posted October 10, 2013 NP manol. I?m just kidding. BUt this would be more of a formbuilder support question. FB is special in that it needs other methods: function hookForm($event){ $form = $event->object; $file = $form->get("file"); print_r($file->attr("value")); } $forms->addHookAfter("InputfieldForm::processInput", null, "hookForm"); echo $forms->load('contact-form')->render(); But I'm not making any money out of form-builder (but Ryan) so I'm not too keen on helping out. I don't mean it really... Also there's some threads about this exactly and you better search via google as mentioned.... Edit: Ok, maybe not so good searching via googel as the form builder forum is private 2 Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 Nice advice to search with google for the general forum, you're not getting money with FB, but whenever you come to Spain for sure as many beers as you can drink. 1 Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2013 Share Posted October 10, 2013 It's also to know what to search I remembered this and looked at FormBuilderProcessor.module, I found this in the FB forum with "formSubmitSuccess" http://processwire.com/talk/topic/4188-managing-successerror-messages/?hl=formsubmitsuccess#entry41151 In case of FB you may want to only hook if the form is submitted successful and you could do this in yet another way (yeah it's not easy) function hookForm($event){ $form = $event->arguments('form'); // as per the argument in the hooked function could also be arguments(0) $field = $form->get("file"); // familiar? print_r($field->value); // file field // do stuff } wire()->addHookAfter("FormBuilderProcessor::formSubmitSuccess", null, "hookForm"); echo $forms->load('contact-form')->render(); Or FormBuilderProcessor::formSubmitError accordingly It's all a little different with formbuilder and I had to try and lookup myself. You can't hook, at least I couldn't find out how (maybe Ryan maybe knows more) into the inputfield processInput directly as with regular InputfieldForms. 1 Link to comment Share on other sites More sharing options...
BUCKHORN Posted October 10, 2013 Share Posted October 10, 2013 NOTE: I'm really sorry but sometimes is really hard to find the right information in the forum, I try hard to found it before making people losing time, and is not a complain at all, people here is in generaly very keen on helping others as I do when I have the knowledge. Tell me about it. The search functionality in this forum doesn't really work well. Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 Hello sshaw it does work well but because there are so many comments sometimes it's hard to find the right information, or these is scattered around. Link to comment Share on other sites More sharing options...
BUCKHORN Posted October 10, 2013 Share Posted October 10, 2013 hmm, I'm doing something wrong. maybe I'm forgetting to change the search from "this topic" to "forum" when I'm searching. Link to comment Share on other sites More sharing options...
Macrura Posted October 10, 2013 Share Posted October 10, 2013 Hi Manol, not sure if this would help, but last time i had to add a hook to FB, i used something like this, in the form-builder.inc file: $forms->addHookBefore('FormBuilderProcessor::saveForm', null, 'hookCampaignMonitor'); function hookCampaignMonitor(HookEvent $event) { $form = $event->object->getInputfieldsForm(); // make sure it's the form you want if ($form->name != 'product-inquiry') return; // grab the data $email = $form->get('email_address')->attr('value'); $first = $form->get('name_first')->attr('value'); $last = $form->get('name_last')->attr('value'); $subscribe = $form->get('subscribe'); $name = $first . ' ' . $last; // check to see if they subscribed if($subscribe->attr('checked')) { $cmurl = 'http://www.example.com/?some-var=' . urlencode($email) . '&cm-name=' . urlencode($name); // post the data $http = new WireHttp(); $http->post($cmurl); } } 2 Link to comment Share on other sites More sharing options...
Manol Posted October 10, 2013 Author Share Posted October 10, 2013 Hello Macrura. Certanly it will help, I'll give it a try tomorrow. Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2013 Share Posted October 13, 2013 $form = $forms->get("reconocimientos"); echo $form->render(); $form->get("reconocimientos")->addHookAfter("processInput", null, 'hookEmail'); A couple things to mention about the above code (quoted from above). You are adding a hook after the render(). You would need to add the hook before the render. That's because processInput is triggered from render(). Secondly is that you are hooking the wrong thing, as I don't think there is a 'processInput' method on $form (since it's not an InputfieldForm). What you'd want to do instead would be this (in your form-builder.inc file): wire()->addHookAfter('FormBuilderProcessor::processInput', null, 'hookProcessInput'); function hookProcessInput(HookEvent $e) { $processor = $e->object; if($processor->formName != 'reconocimientos') return; $inputfields = $processor->getInputfieldsForm(); // your code here. } 2 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