1
votes

Hey guys I am a Drupal Noob so be easy on me. I have created several custom modules with different forms however I was all the time using either a hook_form or hook_output. I was wondering if I can use both in the same module.

I have one module that is supposed to first display a list of courseworks then after the user clicks on any of them it should generate a form for the given course ID.

The way that I generate the list of the students is using hook_output and the list gets generated. The view URL where this happens is this: /drupal/?q=lecturers/evaluate_student/

and the list generated for the courseworks is looks this:

<a href='?q=lecturers/evaluate_student/1/'>Evaluate: <b>Advanced Networking</b></a><br/> 

This practically calls this same ID adding an extra parameter to the URL (/1/ in this case).

The way that I fetch this is using the args():

if (arg(2)) {
        /* Get arguments from URL 
         */
        $coursework_id = arg(2);

    }

Now I would like to generate a form using this ID without redirecting it to another Module. Can I create another hook_form here and call it, if yes how would I do that?

Thanks in advance, -D

1
Notice that Drupal doesn't use any hook_output(). If there is such a hook, that is defined from a third-party module. - apaderno

1 Answers

0
votes

OK so after some time of researching and playing around the solution was not at all complex.

I first created a hook_form:

function evalute_student_form($form, &$form_state){
    $form['coursework_description'] = array(
        '#type' => 'textarea', //you can find a list of available types in the form api
        '#title' => 'Coursework Description:',
        '#size' => 150,
        '#maxlength' => 150,
        '#required' => TRUE, //make this field required 
    );
    return $form;

and then I simply added the return of this method which is $form to the output by using this code:

 if (arg(2)) {
        /* Get arguments from URL and then assign the class to the user.
         */
        $coursework_id = arg(2);
       return evalute_student_form();        
    }

I hope its useful for someone.