Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add content in drupal using custom modules with forms Api
    primarykey
    data
    text
    <p>hook _menu implementation </p> <pre><code>&lt;?php function my_module_menu() { $items = array(); $items['my_module/form'] = array( 'title' =&gt; t('My form'), 'page callback' =&gt; 'my_module_form', 'access arguments' =&gt; array('access content'), 'description' =&gt; t('My form'), 'type' =&gt; MENU_CALLBACK, ); return $items; } function my_module_form() { return drupal_get_form('my_module_my_form'); } // created the custom fields using form api function my_module_my_form($form_state) { $form['name'] = array( '#type' =&gt; 'textfield', '#title' =&gt; t('Name'), ); $form['phone']= array( '#type' =&gt; 'textfield', '#title' =&gt; t('Phone Number'), '#maxlength' =&gt; 10, '#size' =&gt; 10, ); $form['email']= array( '#type' =&gt; 'textfield', '#title' =&gt; 'Email', '#rules' =&gt; array( 'email', ), ); // New form field added to permit entry of year of birth. // The data entered into this field will be validated with // the default validation function. $form['address'] = array( '#type' =&gt; 'textfield', '#title' =&gt; "address", ); $form['choice'] = array( '#type' =&gt; 'radios', '#title' =&gt; t('Gender'), '#options' =&gt; array( t('Male'), t('Female'), t('Transgender'), ) ); $form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; 'Submit', '#submit' =&gt; array('my_module_my_form_submit'), ); return $form; } Done some validation for the form fields function my_module_my_form_validate($form, &amp;$form_state) { $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; $phone = $form_state['values']['phone']; $name = $form_state['values']['name']; $email = $form_state['values']['email']; $address = $form_state['values']['address']; $choice = $form_state['values']['choice']; if (!$name) { form_set_error('name', 'Please enter your name.'); } if (!$phone) { form_set_error('phone', 'Please enter your Phone Number.'); } if (!$email) { form_set_error('email', 'Please enter your Email.'); } else if (!preg_match($regex, $email)) { form_set_error('Email', 'Enter correct Email'); } if (!$address) { form_set_error('address', 'Please enter your Address.'); } if (!isset($choice) ) { form_set_error('choice', 'Please enter your Gender.'); } if (!preg_match('/^[1-9][0-9]*$/',$phone)) { form_set_error('phone', 'Enter correct phone number'); } } function my_module_my_form_submit($form,&amp;$form_state) { drupal_set_message(t('The form has been submitted.')); } </code></pre> <p>?> i am new to drupal i need to know how to implement node save in drupal using Form Api </p> <ol> <li>The fields are validating in submit i need to save the form result in the content page of type Employee </li> <li>i have created the employee content type and the fields are as follows </li> </ol> <p>name phone email address gender i want to save the form value in the content of type employee where employee is teh content type already created plz help me i am new to drupal </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload