sarah_hue Posted April 14, 2015 Posted April 14, 2015 Hi, I've got three fields in a template page: name surname full name (hidden field) Now I'd like "full name" to be a combination of "name" and "surname". There's no need to use javascript, since I only need the "full name" field later on for processing. Would be totally fine to populate "full name" once the page is saved. I don't have any experience with hooks, any hints how I could get the merging done? Thanks sarah
LostKobrakai Posted April 14, 2015 Posted April 14, 2015 http://modules.processwire.com/modules/fieldtype-concat/ 3
blad Posted April 14, 2015 Posted April 14, 2015 https://processwire.com/talk/topic/2458-module-fieldtypeconcatenate/ Fast LostKobrakai 2
sarah_hue Posted April 14, 2015 Author Posted April 14, 2015 Great, thanks a lot! Extra question: If I want to add "Name: " as extra text to the new combined field – how could I do this?
bernhard Posted April 16, 2015 Posted April 16, 2015 you can create an autoload module that adds this on save via a hook: look at site/modules/helloworld.module copy+rename it to eg addNameOnSave.module edit classname + content of getModuleInfo() install + test it - it should say "helloworld ..." after save edit your init function: public function init() { $this->pages->addHookAfter('saveReady', $this, 'saveactions'); } remove the helloworld functions and add this one: /** * do some actions on saving */ public function saveactions($event) { $page = $event->arguments('page'); if($page->template == 'your_template') { $page->fullname = "Name: " . $page->forename . " " . $page->surname; } } not tested, hope i did not forget anything 1
arjen Posted April 16, 2015 Posted April 16, 2015 If the use case is to put a label before the field in the page tree you can also use css (:before with "content"). 1
bernhard Posted April 16, 2015 Posted April 16, 2015 or on frontend templates: echo "Name: " . $page->fullname; definitely depends on where you want to add "Name: "
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