0

I am trying to create my first module in drupal 6. I just need to add some new fields to the already existing comment form(comment module). Eg: City,Email and state fields.

I have created 2 files: 1. mmcomment.module 2. mmcomment.info

Used a function hook_form_alter() like this:

 function mmcomment_form_alter(&$form, $form_state, $form_id) { // form override
 if ($form_id == 'comment_form') {
    // unset the other field elements

    $form['subject'] = array(
      '#access' => FALSE
    );
    $form['comment_filter']['comment'] = array(
      '#access' => FALSE
    );
    // add field to all comments

    $form['Email'] = array(
      '#type' => 'textfield',
      '#title' => t('Email Address'),
      '#maxlength' => 255,
      '#size' => 30,
      '#required' => 1,
      '#weight' => 1,
      '#default_value' => $email
    );
     $form['displayName'] = array(
      '#type' => 'textfield',
      '#title' => t('Display Name'),
      '#maxlength' => 255,
      '#size' => 30,
      '#weight' => 2,
      '#default_value' => $displayName
    );

    $form['_author'] = array(
      '#access' => FALSE
    );
    $form['author'] = array(
      '#access' => FALSE
    );

I need to get the form values and insert into DB. What Function can I use for the same. I have tried: hook_nodeapi(mmcomment_nodeapi). But can't get the form values. Any suggestions.. Thanks

1

In the $form structure you have to add/override the submit (and maybe the validate) handler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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