1

I have a three form fields like Name,phone,email now after inserting the values in my db i want to display the values into same page or another page like Name:XXXXXXXXXXX Phone:5545445454 email:[email protected]

how can do this in drupal7

3
  • Is it about custom form and custom table in DB?
    – ya.teck
    Mar 22, 2013 at 6:09
  • @Xio is it like custom form
    – user22455
    Mar 22, 2013 at 6:14
  • @user22455 updated my answer.
    – AjitS
    Mar 22, 2013 at 10:09

2 Answers 2

2

You can use the function hook_form_FORM_ID_alter to do that.

Just replace the FORM_ID with the ID of your form.
Lets say the id of the form is my_custom_form, then the values could be printed as,

function MODULE_form_my_custom_form_alter(&$form, &$form_state, $form_id){
  //add a new function(submit handler) on submit button.    
  $form['#submit'][] = 'new_submit_function';
}

function new_submit_function(&$form, &form_state) {
  // the $form_state['values'] array contains all the 
  // values from the fields of the current form stored in it
  drupal_set_message("name : " . $form_state['values']['name']);
  drupal_set_message("phone : " . $form_state['values']['phone']);
  //and so on.
  //the message will be displayed on the page after form submit
}

If you are not sure how to find the id of the form, then use hook_form_alter to do that, e.g.

function MODULE_form_alter(&$form, &$form_state, $form_id) {
  drupal_set_message($form_id);
}

this would print the form id of every form you are on, so that you can use the id of the form you wish to change and perform a hook_form_FORM_ID_alter to change anything you wish :-)

1

If it is a custom form then in the submit function where you are inserting the records to the database, you can print the values on that page also. All the values of the form are in the $form_state array.

You can display the values in drupal_set_message() function or using the theme() function.

OR if you want to display the values on another page after submit then you should define the action for your form like $form['#actions'] = url('node/xxx').

2
  • How can i post the values to next page
    – user22455
    Mar 22, 2013 at 10:05
  • when you set the form action to that page, the form values automatically posted to that page when you submit the form.
    – Ahmad
    Mar 25, 2013 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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