1

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.

3

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.

0
1

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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