Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

To style the form from theme layer, refer to How to a use a template file to theme a form?

To style the form from theme layer, refer to How to a use a template file to theme a form?

Fix grammar, enhance formatting, correct typos, etc
Source Link

When dealing with Form API in Drupal 7 there have tow partsare two major steps:

  • create and implement form in module In this step you are set up the Form ,Validate and submit.

     function form_example() {
        $form['first_name']=array(
        '#type' => 'textfield',
        '#title' => t('First name'),
        '#description' => t('Enter first name'),
         );
         $form['last_name']=array(
         '#type' => 'textfield',
         '#title' => t('Last name'),
         '#description' => t('Enter last name'),
         );
     $form['submit_button'] = array(
         '#type' => 'submit',
         '#value' => t('Click Here!'),
         );
    
     return $form;
     } 
    
     function form_example_validate($form, &$form_state) {
    
     }
     function form_example_submit($form, &$form_state) {
    
     }
    

Step 1: Create and implement the form in a module

In this step 1, you will setup the form, and then validate and submit the form, as further detailed below.

a) Setup the form

    function form_example() {
       $form['first_name']=array(
       '#type' => 'textfield',
       '#title' => t('First name'),
       '#description' => t('Enter first name'),
        );
        $form['last_name']=array(
        '#type' => 'textfield',
        '#title' => t('Last name'),
        '#description' => t('Enter last name'),
        );
    $form['submit_button'] = array(
        '#type' => 'submit',
        '#value' => t('Click Here!'),
        );

    return $form;
    } 

    function form_example_validate($form, &$form_state) {

    }
    function form_example_submit($form, &$form_state) {

    }

b) Validate and submit the form

Now the form is ready to displaybe displayed. one

One way to display the form, is usingto theme ofthe form in the module toand then print the form.

Then create theme-contact-form.tpl.phptheme-contact-form.tpl.php in the module file and print the form:

With all previous steps for create and implementcomplpeted, the form is created and implemented in the module.

  • Style form from theme layer as in this question

Step 2: style the form

To style the form from theme layer, refer to How to a use a template file to theme a form?

When dealing with Form API in Drupal 7 there have tow parts:

  • create and implement form in module In this step you are set up the Form ,Validate and submit.

     function form_example() {
        $form['first_name']=array(
        '#type' => 'textfield',
        '#title' => t('First name'),
        '#description' => t('Enter first name'),
         );
         $form['last_name']=array(
         '#type' => 'textfield',
         '#title' => t('Last name'),
         '#description' => t('Enter last name'),
         );
     $form['submit_button'] = array(
         '#type' => 'submit',
         '#value' => t('Click Here!'),
         );
    
     return $form;
     } 
    
     function form_example_validate($form, &$form_state) {
    
     }
     function form_example_submit($form, &$form_state) {
    
     }
    

Now the is ready to display. one way to display form is using theme of module to print form.

Then create theme-contact-form.tpl.php in module file and print form

all previous steps for create and implement form in module.

  • Style form from theme layer as in this question

When dealing with Form API in Drupal 7 there are two major steps:

Step 1: Create and implement the form in a module

In this step 1, you will setup the form, and then validate and submit the form, as further detailed below.

a) Setup the form

    function form_example() {
       $form['first_name']=array(
       '#type' => 'textfield',
       '#title' => t('First name'),
       '#description' => t('Enter first name'),
        );
        $form['last_name']=array(
        '#type' => 'textfield',
        '#title' => t('Last name'),
        '#description' => t('Enter last name'),
        );
    $form['submit_button'] = array(
        '#type' => 'submit',
        '#value' => t('Click Here!'),
        );

    return $form;
    } 

    function form_example_validate($form, &$form_state) {

    }
    function form_example_submit($form, &$form_state) {

    }

b) Validate and submit the form

Now the form is ready to be displayed.

One way to display the form, is to theme the form in the module and then print the form.

Then create theme-contact-form.tpl.php in the module file and print the form:

With all previous steps complpeted, the form is created and implemented in the module.

Step 2: style the form

To style the form from theme layer, refer to How to a use a template file to theme a form?

  • create and implement form in module In this step you are set up the Form ,Validate and submit.

    function form_example() { $form['first_name']=array( '#type' => 'textfield', '#title' => t('First name'), '#description' => t('Enter first name'), ); $form['last_name']=array( '#type' => 'textfield', '#title' => t('Last name'), '#description' => t('Enter last name'), ); $form['submit_button'] = array( '#type' => 'submit', '#value' => t('Click Here!'), );

    return $form; }

    function form_example_validate($form, &$form_state) {

    } function form_example_submit($form, &$form_state) {

     function form_example() {
        $form['first_name']=array(
        '#type' => 'textfield',
        '#title' => t('First name'),
        '#description' => t('Enter first name'),
         );
         $form['last_name']=array(
         '#type' => 'textfield',
         '#title' => t('Last name'),
         '#description' => t('Enter last name'),
         );
     $form['submit_button'] = array(
         '#type' => 'submit',
         '#value' => t('Click Here!'),
         );
    
     return $form;
     } 
    
     function form_example_validate($form, &$form_state) {
    
     }
     function form_example_submit($form, &$form_state) {
    
     }
    

}

function mytheme_theme($existing, $type, $theme, $path) {
   'theme_contact_form' => array (
        'variables' => array(
            'contact_form' => FALSE,
            ),
        'template' =>'theme-contact-form',
    ),
 }
function mytheme_block_info() {
   $blocks['block_contact_form'] = array(
      'info' => t('My Theme Contact form'),
      );
   return $blocks;
}
function mytheme_block_view($delta = '') {
  $block = array();
  switch ($delta) {
  case 'block_contact_form':
        $block['content'] = array(
            '#theme' => 'theme_contact_form',
            '#contact_form' => drupal_get_form('form_example'),
            );
        break;
  }
  return $block;
}

function mytheme_block_info() { $blocks['block_contact_form'] = array( 'info' => t('My Theme Contact form'), ); return $blocks; } function mytheme_block_view($delta = '') { $block = array(); switch ($delta) { case 'block_contact_form': $block['content'] = array( '#theme' => 'theme_contact_form', '#contact_form' => drupal_get_form('form_example'), ); break; } return $block; } ThenThen create theme-contact-form.tpl.php in module file and print form

  • create and implement form in module In this step you are set up the Form ,Validate and submit.

    function form_example() { $form['first_name']=array( '#type' => 'textfield', '#title' => t('First name'), '#description' => t('Enter first name'), ); $form['last_name']=array( '#type' => 'textfield', '#title' => t('Last name'), '#description' => t('Enter last name'), ); $form['submit_button'] = array( '#type' => 'submit', '#value' => t('Click Here!'), );

    return $form; }

    function form_example_validate($form, &$form_state) {

    } function form_example_submit($form, &$form_state) {

}

function mytheme_theme($existing, $type, $theme, $path) {
   'theme_contact_form' => array (
        'variables' => array(
            'contact_form' => FALSE,
            ),
        'template' =>'theme-contact-form',
    ),
 }

function mytheme_block_info() { $blocks['block_contact_form'] = array( 'info' => t('My Theme Contact form'), ); return $blocks; } function mytheme_block_view($delta = '') { $block = array(); switch ($delta) { case 'block_contact_form': $block['content'] = array( '#theme' => 'theme_contact_form', '#contact_form' => drupal_get_form('form_example'), ); break; } return $block; } Then create theme-contact-form.tpl.php in module file and print form

  • create and implement form in module In this step you are set up the Form ,Validate and submit.

     function form_example() {
        $form['first_name']=array(
        '#type' => 'textfield',
        '#title' => t('First name'),
        '#description' => t('Enter first name'),
         );
         $form['last_name']=array(
         '#type' => 'textfield',
         '#title' => t('Last name'),
         '#description' => t('Enter last name'),
         );
     $form['submit_button'] = array(
         '#type' => 'submit',
         '#value' => t('Click Here!'),
         );
    
     return $form;
     } 
    
     function form_example_validate($form, &$form_state) {
    
     }
     function form_example_submit($form, &$form_state) {
    
     }
    
function mytheme_theme($existing, $type, $theme, $path) {
   'theme_contact_form' => array (
        'variables' => array(
            'contact_form' => FALSE,
            ),
        'template' =>'theme-contact-form',
    ),
 }
function mytheme_block_info() {
   $blocks['block_contact_form'] = array(
      'info' => t('My Theme Contact form'),
      );
   return $blocks;
}
function mytheme_block_view($delta = '') {
  $block = array();
  switch ($delta) {
  case 'block_contact_form':
        $block['content'] = array(
            '#theme' => 'theme_contact_form',
            '#contact_form' => drupal_get_form('form_example'),
            );
        break;
  }
  return $block;
}

Then create theme-contact-form.tpl.php in module file and print form

deleted 13 characters in body
Source Link
Loading
Source Link
Loading