I have a question about add a node which have a specific field!

I create two buttons on different page called A,B.

When User touched the A button,i redirect the user to the node_form page.

The specific field default value will be set as ValueA.

When the user touched the B buttons,the value of the specific field will become ValueB.

So i cant user hook_node_form_alter.

I want to write the code at the myform_submit() because of touching the button.

How can i do that?

Are there any method which can change the form value not via the form_alter()?

Please Help Me fix this problem! Thank you!

  • 2
    If by touching both A & B buttons they get redirected to same form page you can use form alter and set a default value. For this you need to know which was touched by passing the button as a parameter when redirecting like touching A it will go to my_form/button_a – GoodSp33d Jul 20 '12 at 5:03
  • @kantu: That is an answer :) – Berdir Jul 20 '12 at 9:25

Let assume you want to create a page. Then create button A which redirect user to /node/add/page?button=a and button B redirect to /node/add/page?button=b

Then in your module create hook_form_alter for node form

function MODULE_node_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#node']->type == 'page') {
    if ($_GET['button'] == 'a') {
      $form['FIELD_NAME']['und'][0]['#default_value'] = 'aaa';
    elseif ($_GET['button'] == 'b') {
      $form['FIELD_NAME']['und'][0]['#default_value'] = 'bbb';
    else {
      $form['FIELD_NAME']['und'][0]['#default_value'] = 'ccc';

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.