Jump to content

Merge/combine two text fields


sarah_hue
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 :)

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...