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