how to display any message or data in mymodule.module file in drupal 7
i have used following line but it didn't display any thing
drupal_set_message(t('test message'));
aslo i want to display any variable data like for example $data = "hello"
then how to display this variable data in drupal 7
i am new to drupal , so if any one knows please let me know .
i have search a lot , but didn't get anything.
thanks in advance.
I have used folllowing code by creating module in drupal 7
<?php
function form_example_menu() {
$items = array();
$items['form_example/form'] = array(
'title' => 'Example Form', //page title
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_example_form'),
'access arguments' => array('access content'), //put the name of the form here
'access callback' => TRUE
);
return $items;
}
function form_example_form($form, &$form_state) {
$form['price'] = array(
'#type' => 'textfield',
'#title' => 'What is Your Price?',
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE, //make this field required
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
$form['form_example_form']['#submit'][] = 'form_example_form_submit';
return $form;
}
function form_example_form_validate(&$form, &$form_state) {
if (!($form_state['values']['price'] > 0)){
form_set_error('price', t('Price must be a positive number.'));
}
}
function form_example_form_submit($form, &$form_state) {
$result = db_insert('test')->fields(array('price' => $form_state['values']['price'],))->execute();
drupal_set_message(t('Your Price was saved'));
}
In above code data is inserted in database , but message didn't displaying . If you know , what is problem please let me know , i have search a lot for this problem . Thanks in advance.
drupal_set_message(t('test message'));
?! – Muhammad Redadpm('Your price was saved')
with the devel module instead. It will also print out variables in a nice format for you if you diddpm($data)
– nmc