php - Storing data from custom module form into content type -
I am looking for a way to save data collected by a form (This form is being generated from the module On). I would like to save the data to a content type that I also created. Is this possible? I am looking for a way to do this and I have not found any easy way to do this. I am currently working on Drupal 7.
My code is:
function drupalform_menu () {$ items ['drupalform / form1'] = array ('type' => MENU_CALLBACK, '' Access logic '= & gt; array (' access content '),' page callback '= & gt;' drupal_get_form ',' page logic '=> array (' drupalform_form1 ')); Return $ item; } Function drupalform_form1 () {$ form = array (); Array ('Form' = ' M '' Shree ',' MME ')); $ Form ['nom'] = array ('#type' => gtk; 'textfield', '# title' = & gt; t ('entrance water name'),); $ Form ['email'] = array ('#type' = & gt; 'textfield', '#title' = & gt; T ('Enter voter e-mail'),); $ Form ['submit'] = Array ('#type' = & gt; 'Submit', '#value' = & gt; t ('Submit')); $ Form return; } Function drupalform_form1_validate ($ form, $ form_state) {if (below ($ form_state ['values'] ['nom'])) form_set_error ('nom', 'vuillez saisir votre nom'); Otherwise if (filter_var ($ form_state ['values'] ['email'], FILTER_VALIDATE_EMAIL) == incorrect) form_set_error ('email', 'mail non valide'); } Function drupalform_form1_submit ($ form, $ form_state) {drupal_set_message ("Lee Formulaire Live"); Drupal_goto (); }
You can create nodes by specifying such values,
global $ user; $ NewNode = new stud class (); $ NewNode- & gt; Type = 'NODE_TYPE'; $ NewNode- & gt; Title = 'NODE_TITLE' $ newNode- & gt; UID = $ Usage-> UID; $ NewNode- & gt; Created = Strottomman ("now"); $ NewNode- & gt; Converted = Strottomman ("now"); $ NewNode- & gt; Condition = 1; $ NewNode- & gt; Comment = 0; $ NewNode- & gt; Boost = 0; $ NewNode- & gt; Medium = 0; $ NewNode- & gt; Sticky = 0; // CCK field data $ newNode- & gt; Add Field_YOUR_CUSTOM_FIELD_NAME_1 [0] ['value'] = 'FORM_VALUE_1'; $ NewNode- & gt; Field_YOUR_CUSTOM_FIELD_NAME_2 [0] ['value'] = 'FORM_VALUE_2'; // Save node node_save ($ newnode);
You can submit it to your form.
Comments
Post a Comment