PHP Classes

drupal6 form problem

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  drupal6 form problem  
Subject:drupal6 form problem
Summary:drupal form messages showing elsewhere.
Messages:2
Author:subhajit.techshu
Date:2010-08-13 08:51:18
Update:2010-08-25 20:35:26
 

  1. drupal6 form problem   Reply   Report abuse  
Picture of subhajit.techshu subhajit.techshu - 2010-08-13 15:07:35
Hi,

I am a newbie to drupal6.I have created a module for creating and accessing a form.

For this I created the form code:
/*
* User side form creation
*/
function freequote_message_form_user()
{
$form['#name'] = 'frm';
$form['freequote_name'] = array(
'#type' => 'textfield',
'#title' => t('Your Name'),
'#size' => 39,
'#attributes' => array('class' => 'form-input'),
'#default_value' => $row['name'],
'#suffix' => '<br /><br />',
'#hidedefault' => 1,
);
$form['freequote_email'] = array(
'#type' => 'textfield',
'#title' => t('Your Email'),
'#size' => 39,
'#attributes' => array('class' => 'form-input'),
'#default_value' => $row['email'],
'#suffix' => '<br /><br />',
'#hidedefault' => 1,
);
$form['freequote_phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#size' => 39,
'#attributes' => array('class' => 'form-input'),
'#default_value' => $row['phone'],
'#suffix' => '<br /><br />',
'#hidedefault' => 1,
);
$form['freequote_message'] = array(
'#type' => 'textarea',
'#default_value' => $row['message'],
'#cols' => 30,
'#rows' => 5,
'#attributes' => array('class' => 'form-input'),
'#hidedefault' => 1,
);
//Submit button:

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Message'),
'#hidedefault' => 1,
);

return $form;
}

And for field validation

/*
* For User
* form validation function
*/
function freequote_message_form_user_validate($form, &$form_state)
{
if ($form_state['values']['freequote_name'] == '')
{
form_set_error($form, t('You must select a name.'));
}
if ($form_state['values']['freequote_email'] == '')
{
form_set_error($form, t('You must give an email.'));
}
if ($form_state['values']['freequote_message'] == '')
{
form_set_error($form, t('You must put up a message.'));
}

}

And for inserting form data I am using:

/*
* For User
* Submitting the form and inserting to database table
*/
function freequote_message_form_user_submit($form, &$form_state)
{
$sql = "insert into {custom_freequote} set
name = '".$form_state['values']['freequote_name']."',
email = '".$form_state['values']['freequote_email']."',
phone = '".$form_state['values']['freequote_phone']."',
message = '".$form_state['values']['freequote_message']."',
replied = '0',
post_date = NOW() ";

$exe_query = db_query($sql);
if ($exe_query !== false)
{ drupal_set_message(t('Your form has been saved.'), 'custommessage'); }
else
{ drupal_set_message(t('Could not save message.')); }

$form_state['redirect'] = $_GET['q'];
}


The problem is I could neither set the error message on top of the form nor is the success message showing in the right place(on top of the form).The messages are showing elsewhere.

Please help me...

Thanks anyways....

There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.