Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a form from a unique content type which has two fields, when I submit that form, I wish the value entered in the second field was "included" in the end of the first field and then the content type saves.

Like

field1, value: "John"
field2, value: "Doo"

but when the content type is saved, this happens:

field1, value: "John Doo" // the space which divide the two words is required as well.
field2, value: "Doo"

thanks.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

I would suggest you hook_node_presave() for this. Write this function somewhere in your custom module, just print the $node array. You would found all the fields value there that you can alter accordingly. Your code should be something like this.

function mymodule_node_presave($node) {
  if ($node->type == 'content type name') {
   // Append last name field value with first name field.
  }
}

This hook function get executed before node_save() that will save your changes in db.

share|improve this answer
    
Thanks a Lot, I'm gonna try it. –  Khronna Jun 10 at 11:39
add comment

Hook_form_alter() would be another option. You can grab the form values in a custom submit handler. Code would look something like this:

function yourmodule_form_alter(&$form,&$form_state,$form_id)
{
     if($form_id == "your_node_form_id")
     {
          $form['#submit'][] = '_yourmodule_form_custom_submit_handler';
     }
}

function _yourmodule_form_custom_submit_handler($form,$form_state)
{
     //here you can grab and alter the $form_state values accordingly
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.