SHARE
TWEET

Untitled

a guest Sep 5th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function kostenrechner_permission() {
  2.   return array(
  3.     'view kostenrechner block' => array(
  4.       'title' => t('View Calculate block'),
  5.       'description' => t('Calculate cost of german divorce')
  6.     ),
  7.   );
  8. }
  9.  
  10.  
  11. function kostenrechner_menu() {
  12.   $items = array();
  13.  
  14.   $items['examples/kostenrechner'] = array(
  15.     'title' => 'Kostenrechner',
  16.     'description' => 'A form to mess around with.',
  17.     'page callback' => 'drupal_get_form',
  18.     'page arguments' => array('kostenrechner_form'),
  19.     'access callback' => TRUE,
  20.     'type' => MENU_NORMAL_ITEM,
  21.   );
  22.  
  23.   return $items;
  24. }
  25.  
  26. function kostenrechner_form($form, &$form_state) {
  27.   $form['einkommen'] = array(
  28.     '#type' => 'textfield', //you can find a list of available types in the form api
  29.     '#title' => 'Ihr Einkommen',
  30.     '#size' => 10,
  31.     '#maxlength' => 10,
  32.     '#required' => TRUE, //make this field required
  33.     '#default_value' => isset($form_state['storage']['einkommen']) ? $form_state['storage']['einkommen'] : '',
  34.   );
  35.   $form['einkommen_partner'] = array(
  36.     '#type' => 'textfield', //you can find a list of available types in the form api
  37.     '#title' => 'Das Einkommen Ihres Partners',
  38.     '#size' => 10,
  39.     '#maxlength' => 10,
  40.     '#required' => TRUE, //make this field required
  41.     '#default_value' => isset($form_state['storage']['einkommen_partner']) ? $form_state['storage']['einkommen_partner'] : '',
  42.   );
  43.   $form['kind'] = array(
  44.     '#type' => 'textfield', //you can find a list of available types in the form api
  45.     '#title' => 'Wie viele Kinder haben Sie?',
  46.     '#size' => 10,
  47.     '#maxlength' => 10,
  48.     '#required' => TRUE, //make this field required
  49.     '#default_value' => isset($form_state['storage']['kind']) ? $form_state['storage']['kind'] : '',
  50.   );
  51.  
  52.   $form['submit_button'] = array(
  53.     '#type' => 'submit',
  54.     '#value' => t('Kosten berechnen'),
  55.   );
  56.  
  57. return $form;
  58. }
  59.  
  60. function kostenrechner_form_validate($form, &$form_state) {
  61.    
  62.      if (
  63.      !($form_state['values']['einkommen'] > 0) or !is_numeric($form_state['values']['einkommen'])
  64.      
  65.      ){
  66.     form_set_error('price', t('Bitte geben Sie Ihr Einkommen an'));
  67.   }
  68.     if (
  69.     !($form_state['values']['einkommen_partner'] >= 0) or !is_numeric($form_state['values']['einkommen_partner'])
  70.     ){
  71.     form_set_error('price', t('Bitte geben Sie Ihr Einkommen Ihres Partners an'));
  72.   }
  73.  
  74. }
  75.  
  76. function kostenrechner_form_submit($form, &$form_state) {
  77.  
  78. /*** Hier die Berechnung ***/
  79.  
  80. if(isset($result))
  81.     {
  82.  
  83.     print $result;
  84.     }
  85.     else
  86.     {
  87.     print 'result is clear';
  88.     }
  89. $form_state['rebuild'] = TRUE;
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top