2

I've got a moderation form in the admin section, where a moderator can edit the text, the user has written.

Here is my form:

function phase2_moderation_form($admin, $moderation, $phase2, $edit, $sdid) {

    $sql = 'SELECT * FROM {phase2_submitted_data} WHERE sdid = :sdid';
    $results = db_query($sql, array(':sdid' => $sdid));
    foreach ($results as $result) {
        $submission[] = $result;
    }

    $form = array(); 

    $form['status'] = array(
    '#type' => 'select',
    '#title' => t('Status'),
    '#options' => array(
            '0' => t('not enabled'),
            '1' => t('enabled')
            ),
    '#required' => TRUE,
    '#value' => $submission[0]->status,
    );

    $form['question'] = array(
            '#type' => 'textarea',
            '#title' => t('question'),
            '#required' => TRUE,
            '#value' => $submission[0]->question,
    );

    $form['topic'] = array(
            '#type' => 'select',
            '#title' => t('topic'),
            '#options' => array(
                    'social' => t('Social'),
                    'culture' => t('Culture'),
                    'government' => t('Government'),
                    'environment' => t('Environment'),
                    'traffic' => t('Traffic'),
                    'other' => t('Other')
                    ),
            '#default_value' => 'other',
            '#required' => TRUE,
            '#attributes' => array('id' => array('topic'), 'name' => array('topic')),
            '#title_display' => 'before',
            '#value' => $submission[0]->topic,
            );
    $form['answer'] = array(
            '#type' => 'textarea',
            '#title' => t('Our Answer'),
            '#required' => FALSE,
            '#value' => $submission[0]->answer,
            '#title_display' => 'before',
            );
    $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Submit'),
            );
    $form['#submit'][0] = 'phase2_moderation_edit_form_submit';
    $form['cancel'] = array(
            '#type' => 'button',
            '#value' => t('Cancel'),
    );
    return $form;
}

Actually nothing special, but there is no form-tag rendered.

In Firebug, I see that there are the form-element-divs, but there is no around that divs. I already tried to comment out the Cancel-Button, but that doesn't help.

Could you please help me?

Here is the hook_menu:

function phase2_menu() {
    $items = array();
    $items['admin/moderation/phase2/edit/%'] = array(
        'title' => t('Moderation Phase 2'),
        'page callback' => 'phase2_moderation_form',
        'page arguments' => array(0,1,2,3,4),
        'access arguments' => array('moderation phase 2'),
        'file' => 'phase2.moderation.form.inc',
    );
 return $items;
}

I do not call anything extra (no preprocess-function or tpl.php) or anything else. I thought Drupal render it itself by a function deep inside.

Bye Tom

  • Have you tried it with standard theme like Bartik? – Mołot Jul 25 '13 at 11:38
  • How do you render that form?, my guess is that the form's children (hidden fields) are missing also.. – Pan Chrono Jul 25 '13 at 11:41
  • @Molot: It is the seven theme, I use in this case – Tom Jul 25 '13 at 11:54
  • @PanChrono: I do not render the form explicitly. Where (in which function) do I have to say drupal_get_form()? – Tom Jul 25 '13 at 11:54
  • Please show us code you use to render it. We can't quite tell where in it you should call certain functions if we can't see it in the first place. – Mołot Jul 25 '13 at 11:56
4

I think you need to use 'drupal_get_form' as a page callback and use array('phase2_moderation_form', 0, 1, 2, 3, 4) as page arguments

Or you can change the page callback to another function, like for example 'phase2_get_my_form' and in that function call return drupal_get_form('phase2_moderation_form', $arg0, $arg1, $arg2, $arg3, $arg4); (obviously change the $argX to your proper argument names.)

  • 1
    aahh, coooool :) now, there is the form, but my sql-statement doesn't work. I think I try you second version and try to query the db in the other function. Thank you @Beebee – Tom Jul 25 '13 at 13:25
  • 1
    You should be able to query the database from any function, there are no restrictions as far as I know, except for when drupal is not yet bootstrapped, but that shouldn't happen in your case. Please double check your code or even better, strip it down to its absolute basics (make a backup of your current code first!), and go from there. – Beebee Jul 25 '13 at 13:50

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.