How do I use hook_form to create a frontend node form?

Go To StackoverFlow.com

1

I have created a custom module and have used 'hook_form' to create a custom form. I have then created a new page using menu callback and inserted this form on it

This form basically is to create nodes from the frontend. I have all the same fields as in the backend.

Form code:

function input_simple_form($form, &$form_submit) {

$form['title'] = array(
  '#type' => 'textfield',
  '#default_value' => '',
  '#required' => TRUE,
  '#title' => 'Title',
  '#maxlength' => 1024,
);

$form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
);

return $form;

}

How do I save this, or how do I tell the hook_form that this is for a specific content type? I know how to use node_save but not sure how I would implement this with the hook_form.

How do I go about achieving what I want?

Thanks Robert

2012-04-05 01:56
by Rob Fyffe


0

Use in your callback function:

$my_form = drupal_get_form('input_simple_form');
echo $my_form;

if your are using hook_theme to theme your page parce $my_form as variable and print it in your template/theme file.

2012-04-06 11:50
by kkatusic
Ads