Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:25:08+00:00 2026-06-05T04:25:08+00:00

I am creating a custom form with 4 fields & I want to create

  • 0

I am creating a custom form with 4 fields & I want to create a node of a particular content type, which is having some CCK fields.

I am intended to create node pro-grammatically on submission of this form. I have plan to push default values for some fields and some fields will be mapped with this form widgets..

Here is my code

 <?php

require 'modules/node/node.pages.inc';

/**
 * Implements hook_menu().
 */

function taskform_menu() {
  $items = array();
  $items['admin/content/taskform'] = array(
    'title' => 'Add Task',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('taskform_form'),
    'access arguments' => array('create create_task content'),
  ); 
  return $items;
}
 global $user;

function taskform_perm() {
  return array('Submit daily task');
}

function taskform_form(&$node)
{


  $form['date'] = array(
    '#type' => 'date', 
    '#title' => t('Date'),        
  );

  $form['edproject'] = array(
    '#type' => 'select', 
    '#title' => t('Project'), 

    '#options' => array(
      1 => 'Konnected', 
      2 => 'eLearning', 
      3 => 'Others',
    ),
    '#description' => t('Choose a project'),
  );

  $form['task'] = array(
    '#type' => 'textfield', 
    '#title' => t('Task'), 
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 30,
    '#description' => t('Enter the task'),
  );

  $form['remarks'] = array(
    '#type' => 'textfield', 
    '#title' => t('Remarks'), 
    '#size' => 30,
    '#description' => t('Enter remarks (If any).'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add Task'),
    '#submit' => array('taskform_form_submit'),
  );
  return $form;

}

function taskform_form_submit($form, &$form_state) {

  $node = new stdClass();
  $node->type = 'create_task';
  $node->uid = $user->uid;
  $node->title = $form_state['values']['task'];
  $node->body = $form_state['values']['task'];
  $node->status = 1;
  $node->promote = 0;
  $node->field_assigned_uid[]['uid'] = $user->uid;
  node_object_prepare($node);
    $node = node_submit($node);
    if ($node->validated) {
        node_save($node);
    }
    else{
        t("Node not created");
    }


}

Now when I am submitting this, It’s creating the content type with the text-field text as title & body which I am intended to do…but I want to store UID(logged in user ID) in uid column of the table node…and I have tried doing it as you can see…but still it’s sending 0…
I need help on this…please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:25:10+00:00Added an answer on June 5, 2026 at 4:25 am

    IMO, it’s not a too good idea to make a node for each webform submission. Lame.
    You can always tailor node form to do what webform does so it’s a straight forward setup. Also, you can access each submission’s data easily, and webform already has Views integration so I don’t know why you need to create a node.

    However, if you still need to go ahead, the best way I’d suggest is using webform’s new hooks (since Webform 3).
    See hook_webform_submission_insert

    <?php
    function MYMODULE_webform_submission_insert($node, $submission) {
    // print the submitted values object's information as a message.
    // Once you have grabbed the necessary data, remove this line. 
    drupal_set_message('<pre>'.print_r($submission, TRUE).'</pre>');
    
    // Now, grab the fields you want and map them to the $node object below.
    $node = new stdClass();
    $node->title   = 'Webform submission: '$submission->sid;
    $node->body    = 'test body';
    $node->type    = 'story';
    $node->created = time();
    $node->status  = 1; //published.
    $node->promote = 1; 
    $node->sticky  = 0;
    $node->format  = 1;
    $node->uid     = 1; // author!
    
    if ($node = node_submit($node)) {
      node_save($node);
    }
    else {
      // error creating node. 
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having some problems creating a custom search form for jqGrid, on the last
I have mastered creating custom data types and adding fields with CCK. Then I
I am creating a custom JPanel element (a login form). I want to allow
I am creating a custom form type in symfony2. But every time I try
I want to create a custom form that a user can fill out for
I was creating custom content model in datalistModel.xml <type name=dl:car> <title>Car List</title> <parent>dl:dataListItem</parent> <properties>
I'm creating an HTML form, which takes some of its options from a database
I am creating a custom zend form element that will require some javascript. I
How would one go about creating a custom form field type for Symfony 2?
I'm creating custom forum software for a site I'm building, which includes 2 tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.