hi,
i am building an enquiry forms with following fields - name, email id ,contact number and text body to fill the enquiry and also i want to display all the enquiries flled by the user in a page. so can anyone please tell me how to build forms in drupal and place the form in sidebar so user can fill the enquiry.thanks in advance.

regards,

-sasi

Comments

Anonymous’s picture

Since we're in the module development forum, there are many resources available for building forms within a custom module, here are a few that can get you started:

Forms API Quickstart Guide

Forms API Reference

There are also some books available that discuss building forms, for example John VanDyk and Matt Westgate's "Pro Drupal Development."

Here's a module that you can look into for helping build forms.

Also, it may be appropriate for your design to create a custom node type (using the Drupal admin console) and associate fields with that node type (using CCK).

Once your form is created, there are a number of ways to put the form into a Drupal "block" which can then be assigned to display in one of the sidebars on your site.

Tyler2499’s picture

Sorry, I don't mean to hijack your thread but I too have a question about forms. Currently I am following the api on creating drop down list and found myself stuck. I am building a custom module but I would like to use the values be the users ID but have it displayed as the username in the drop down.

$racers = array(0=> 'Select a racer');

$sql = "SELECT name FROM {users} ORDER BY name";
  $r = db_query($sql);
 
  // Get each option and populate the options array.
  while ($row = db_fetch_array($r)) {
    $racers[$row['name']] = $row['name'];
  }

$form['racer'] = array(
    '#type' => 'select',
    '#title' => t('Select a racer to add to the league'),
    '#options' => $racers,
    '#description' => t('Racer to add.'),
  );

This gets the username. What I'd like to do is have the value of the option the users ID and have the display text be their username. It works as is but not the way I'd like. Any help is appreciated thanks.

gbarrigap’s picture

I think you just need to query for the users.uid column as well.

$racers = array(0 => 'Select a racer');

$result = db_query('SELECT uid, name FROM {users} ORDER BY name');

// Get each option and populate the options array.
while ($row = db_fetch_array($result)) {
  $uid = $row['uid'];
  $name = $row['name'];

  $racers[$uid] = $name;
}

$form['racer'] = array(
  '#type' => 'select',
  '#title' => t('Select a racer to add to the league'),
  '#options' => $racers,
  '#description' => t('Racer to add.'),
);

That should do it.

Kind regards.

Tyler2499’s picture

How would i go about submitting the variables to the database? Because $form_state['values']['racer'] will get the username not the ID... Thanks for the response.

I tried this previously but I am clueless on how to pass the variable...

gbarrigap’s picture

I don't get it.

You already have the name in the users table, so why do you need to replicate it; you just need the uid.

I figure you have a table for racers only, and in that case, that table should have a uid column referencing to the users table, a column named uid would do it. In that case, with a simple JOIN you can get the name of the racers:

SELECT name FROM users JOIN racers USING (uid)

Thus, to create a new racer, you will do something like this:

// In the submit function:
$racer = new stdClass();
$racer->uid = $form_state['values']['racer'];
// ... you can add more attributes in the same manner.

// Once you have your racer object built, just save it with drupal_write_record:
drupal_write_record('racers', $racer);

http://api.drupal.org/api/function/drupal_write_record/6

Tyler2499’s picture

Maybe you are thinking of something else... On a drop down list you can have a value and a "display text". So the value of the option will be the ID from the users table but on the list it will display the username for that ID. This would make it easier to identify who you are actually adding rather than just seeing numbers (ID's).

A normal select would look like:
<option value="USERID">USERNAME</option>