Skip to main content
improved grammar and punctuation
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

hello so imI am working on thisa module thatwritten by another developer; the module shows pray times and i was tasked with addingI have to add the option for people to select a month and year and show pray times for that month. allAll is going goodfine, but imI am not sure that iI understand how thisthe form for this module was set up because when iI try to use variable_get(praytimes_month);variable_get(praytimes_month), it never hasreturns anything in it, even after sumbittingsubmitting the form.


 

rightRight now, what iI have works, but i cantI can't set the default month because the only way for me to get something into my variable is thruthrough the cookies.

function praytimes_user_settings_form($form, &$form_state) {
        
      if ((variable_get('praytimes_userselect') == 'no')){
    
      $form['overview'] = array(
        '#markup' => t('Access denied!'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
        return $form;
      }
      
      if(!isset($_COOKIE['Drupal_visitor_praytimes_address']))
      {
        $address = variable_get('praytimes_address');
        $tz = variable_get('praytimes_tz');
        $cmonth = variable_get('prayertimes_month',date("m"));
        $cyear = variable_get('prayertimes_year',date("Y"));
      }
      else {
            
        $address = $_COOKIE['Drupal_visitor_praytimes_address'];
        $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
        $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
        $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
          
      }
    
      $form['overview'] = array(
        '#markup' => t('This page allows user to configure City and Time Zone'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
      $form['praytimes_address'] = array(
        '#title' => t('Address'),
        '#description' => t('City, State, Contry or zipcode e.g: Dearborn, MI, USA or 48126'),
        '#type' => 'textfield',
        '#default_value' => $address,
        '#required' => TRUE,
      );
      
      
      $form['praytimes_tz'] = array(
        '#title' => t('Time Zone'),
        '#description' => t('Enter the time zone(e.g. Eastern is -5, Central is -6, Mountain is -7 and Pacific is -8).'),
        '#type' => 'textfield',
        '#default_value' => $tz,
        '#required' => TRUE,
      );
        $form['praytimes_month'] = array(
        '#title' => t('Month'),
        '#description' => t('Please enter a month in number form.'),
        '#type' => 'textfield',
        '#default_value' => $cmonth,
      );
        $form['praytimes_year'] = array(
        '#title' => t('Year'),
        '#description' => t('Please enter a Year.'),
        '#type' => 'textfield',
        '#default_value' => $cyear,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      );
    
      return $form;
    }
    
    /**
     * Process a validated Pray Times user setting submission.
     */
    function praytimes_user_settings_form_submit($form, &$form_state) {
      //Rebuild the form.
    
      $form_state['redirect'] = 'prayertimes/timetable';
    
      $address = $form_state['values']['praytimes_address'];
      $tz = $form_state['values']['praytimes_tz'];
      $cmonth = $form_state['values']['praytimes_month'];
      $cyear = $form_state['values']['praytimes_year'];
      $coord = getLatLong($address);
      $lat = $coord['lat'];
      $long = $coord['long'];
       
      
      user_cookie_save(array(
        'praytimes_month' => $cmonth,
        'praytimes_year' => $cyear,
        'praytimes_address'=> $address, 
        'praytimes_tz' => $tz,
        'praytimes_lat' => $lat,
        'praytimes_long' => $long,));
    
      // Notify user.
      drupal_set_message(t('City and Time Zone settings has been saved.'));
    }
    
    function praytimes_table (){
            
        $output = '';
        
        if(!isset($_COOKIE['Drupal_visitor_praytimes_address'])){
            $address = variable_get('praytimes_address');
            $cmonth = variable_get('prayertimes_month');
            $cyear = variable_get('prayertimes_year');
            $tz = variable_get('praytimes_tz');
            $lat = variable_get('praytimes_lat');
            $long = variable_get('praytimes_long');
          }
          else {
            $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
            $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
            $address = $_COOKIE['Drupal_visitor_praytimes_address'];
            $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
            $lat = $_COOKIE['Drupal_visitor_praytimes_lat'];
            $long = $_COOKIE['Drupal_visitor_praytimes_long'];    
          }
    
        $dst = variable_get('praytimes_dst');
        $today = mktime(0,0,0,$cmonth,1,$cyear);
        $currentmonth = date('F', $today);
        $currentyear = date('Y', $today);
    //  $tempdate = strtotime($currentmonth.'-1-'.$currentyear);
        $tempdate = $today;
        $oneday = 24*60*60

sorry if im confusing cuz im confused as fk as to why this for wouldnt store the values normally and the dude used $_COOKIE


what iWhat I want is to storestoring the submitted month/year submitted thru the form to $tempdate and, if nothing was submitted to, have a default value.

hello so im working on this module that shows pray times and i was tasked with adding the option for people to select a month and year and show pray times for that month. all is going good but im not sure that i understand how this form for this module was set up because when i try to use variable_get(praytimes_month); it never has anything in it even after sumbitting the form.


 

right now what i have works but i cant set default month because the only way for me to get something into my variable is thru the cookies.

function praytimes_user_settings_form($form, &$form_state) {
        
      if ((variable_get('praytimes_userselect') == 'no')){
    
      $form['overview'] = array(
        '#markup' => t('Access denied!'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
        return $form;
      }
      
      if(!isset($_COOKIE['Drupal_visitor_praytimes_address']))
      {
        $address = variable_get('praytimes_address');
        $tz = variable_get('praytimes_tz');
        $cmonth = variable_get('prayertimes_month',date("m"));
        $cyear = variable_get('prayertimes_year',date("Y"));
      }
      else {
            
        $address = $_COOKIE['Drupal_visitor_praytimes_address'];
        $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
        $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
        $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
          
      }
    
      $form['overview'] = array(
        '#markup' => t('This page allows user to configure City and Time Zone'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
      $form['praytimes_address'] = array(
        '#title' => t('Address'),
        '#description' => t('City, State, Contry or zipcode e.g: Dearborn, MI, USA or 48126'),
        '#type' => 'textfield',
        '#default_value' => $address,
        '#required' => TRUE,
      );
      
      
      $form['praytimes_tz'] = array(
        '#title' => t('Time Zone'),
        '#description' => t('Enter the time zone(e.g. Eastern is -5, Central is -6, Mountain is -7 and Pacific is -8).'),
        '#type' => 'textfield',
        '#default_value' => $tz,
        '#required' => TRUE,
      );
        $form['praytimes_month'] = array(
        '#title' => t('Month'),
        '#description' => t('Please enter a month in number form.'),
        '#type' => 'textfield',
        '#default_value' => $cmonth,
      );
        $form['praytimes_year'] = array(
        '#title' => t('Year'),
        '#description' => t('Please enter a Year.'),
        '#type' => 'textfield',
        '#default_value' => $cyear,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      );
    
      return $form;
    }
    
    /**
     * Process a validated Pray Times user setting submission.
     */
    function praytimes_user_settings_form_submit($form, &$form_state) {
      //Rebuild the form.
    
      $form_state['redirect'] = 'prayertimes/timetable';
    
      $address = $form_state['values']['praytimes_address'];
      $tz = $form_state['values']['praytimes_tz'];
      $cmonth = $form_state['values']['praytimes_month'];
      $cyear = $form_state['values']['praytimes_year'];
      $coord = getLatLong($address);
      $lat = $coord['lat'];
      $long = $coord['long'];
       
      
      user_cookie_save(array(
        'praytimes_month' => $cmonth,
        'praytimes_year' => $cyear,
        'praytimes_address'=> $address, 
        'praytimes_tz' => $tz,
        'praytimes_lat' => $lat,
        'praytimes_long' => $long,));
    
      // Notify user.
      drupal_set_message(t('City and Time Zone settings has been saved.'));
    }
    
    function praytimes_table (){
            
        $output = '';
        
        if(!isset($_COOKIE['Drupal_visitor_praytimes_address'])){
            $address = variable_get('praytimes_address');
            $cmonth = variable_get('prayertimes_month');
            $cyear = variable_get('prayertimes_year');
            $tz = variable_get('praytimes_tz');
            $lat = variable_get('praytimes_lat');
            $long = variable_get('praytimes_long');
          }
          else {
            $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
            $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
            $address = $_COOKIE['Drupal_visitor_praytimes_address'];
            $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
            $lat = $_COOKIE['Drupal_visitor_praytimes_lat'];
            $long = $_COOKIE['Drupal_visitor_praytimes_long'];    
          }
    
        $dst = variable_get('praytimes_dst');
        $today = mktime(0,0,0,$cmonth,1,$cyear);
        $currentmonth = date('F', $today);
        $currentyear = date('Y', $today);
    //  $tempdate = strtotime($currentmonth.'-1-'.$currentyear);
        $tempdate = $today;
        $oneday = 24*60*60

sorry if im confusing cuz im confused as fk as to why this for wouldnt store the values normally and the dude used $_COOKIE


what i want is to store the month/year submitted thru the form to $tempdate and if nothing was submitted to have a default value.

I am working on a module written by another developer; the module shows pray times and I have to add the option for people to select a month and year and show pray times for that month. All is going fine, but I am not sure I understand how the form for this module was set up because when I try to use variable_get(praytimes_month), it never returns anything, even after submitting the form.

Right now, what I have works, but I can't set the default month because the only way for me to get something into my variable is through the cookies.

function praytimes_user_settings_form($form, &$form_state) {
      if ((variable_get('praytimes_userselect') == 'no')){
    
      $form['overview'] = array(
        '#markup' => t('Access denied!'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
        return $form;
      }
      
      if(!isset($_COOKIE['Drupal_visitor_praytimes_address']))
      {
        $address = variable_get('praytimes_address');
        $tz = variable_get('praytimes_tz');
        $cmonth = variable_get('prayertimes_month',date("m"));
        $cyear = variable_get('prayertimes_year',date("Y"));
      }
      else {
            
        $address = $_COOKIE['Drupal_visitor_praytimes_address'];
        $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
        $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
        $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
          
      }
    
      $form['overview'] = array(
        '#markup' => t('This page allows user to configure City and Time Zone'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
      $form['praytimes_address'] = array(
        '#title' => t('Address'),
        '#description' => t('City, State, Contry or zipcode e.g: Dearborn, MI, USA or 48126'),
        '#type' => 'textfield',
        '#default_value' => $address,
        '#required' => TRUE,
      );
      
      
      $form['praytimes_tz'] = array(
        '#title' => t('Time Zone'),
        '#description' => t('Enter the time zone(e.g. Eastern is -5, Central is -6, Mountain is -7 and Pacific is -8).'),
        '#type' => 'textfield',
        '#default_value' => $tz,
        '#required' => TRUE,
      );
        $form['praytimes_month'] = array(
        '#title' => t('Month'),
        '#description' => t('Please enter a month in number form.'),
        '#type' => 'textfield',
        '#default_value' => $cmonth,
      );
        $form['praytimes_year'] = array(
        '#title' => t('Year'),
        '#description' => t('Please enter a Year.'),
        '#type' => 'textfield',
        '#default_value' => $cyear,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      );
    
      return $form;
    }
    
    /**
     * Process a validated Pray Times user setting submission.
     */
    function praytimes_user_settings_form_submit($form, &$form_state) {
      //Rebuild the form.
    
      $form_state['redirect'] = 'prayertimes/timetable';
    
      $address = $form_state['values']['praytimes_address'];
      $tz = $form_state['values']['praytimes_tz'];
      $cmonth = $form_state['values']['praytimes_month'];
      $cyear = $form_state['values']['praytimes_year'];
      $coord = getLatLong($address);
      $lat = $coord['lat'];
      $long = $coord['long'];
       
      
      user_cookie_save(array(
        'praytimes_month' => $cmonth,
        'praytimes_year' => $cyear,
        'praytimes_address'=> $address, 
        'praytimes_tz' => $tz,
        'praytimes_lat' => $lat,
        'praytimes_long' => $long,));
    
      // Notify user.
      drupal_set_message(t('City and Time Zone settings has been saved.'));
    }
    
    function praytimes_table (){
        $output = '';
        
        if(!isset($_COOKIE['Drupal_visitor_praytimes_address'])){
            $address = variable_get('praytimes_address');
            $cmonth = variable_get('prayertimes_month');
            $cyear = variable_get('prayertimes_year');
            $tz = variable_get('praytimes_tz');
            $lat = variable_get('praytimes_lat');
            $long = variable_get('praytimes_long');
          }
          else {
            $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
            $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
            $address = $_COOKIE['Drupal_visitor_praytimes_address'];
            $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
            $lat = $_COOKIE['Drupal_visitor_praytimes_lat'];
            $long = $_COOKIE['Drupal_visitor_praytimes_long'];    
          }
    
        $dst = variable_get('praytimes_dst');
        $today = mktime(0,0,0,$cmonth,1,$cyear);
        $currentmonth = date('F', $today);
        $currentyear = date('Y', $today);
    //  $tempdate = strtotime($currentmonth.'-1-'.$currentyear);
        $tempdate = $today;
        $oneday = 24*60*60

What I want is storing the submitted month/year to $tempdate and, if nothing was submitted, have a default value.

Source Link

help with custom module form variable_get();

hello so im working on this module that shows pray times and i was tasked with adding the option for people to select a month and year and show pray times for that month. all is going good but im not sure that i understand how this form for this module was set up because when i try to use variable_get(praytimes_month); it never has anything in it even after sumbitting the form.


right now what i have works but i cant set default month because the only way for me to get something into my variable is thru the cookies.

function praytimes_user_settings_form($form, &$form_state) {
        
      if ((variable_get('praytimes_userselect') == 'no')){
    
      $form['overview'] = array(
        '#markup' => t('Access denied!'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
        return $form;
      }
      
      if(!isset($_COOKIE['Drupal_visitor_praytimes_address']))
      {
        $address = variable_get('praytimes_address');
        $tz = variable_get('praytimes_tz');
        $cmonth = variable_get('prayertimes_month',date("m"));
        $cyear = variable_get('prayertimes_year',date("Y"));
      }
      else {
            
        $address = $_COOKIE['Drupal_visitor_praytimes_address'];
        $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
        $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
        $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
          
      }
    
      $form['overview'] = array(
        '#markup' => t('This page allows user to configure City and Time Zone'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
        
      $form['praytimes_address'] = array(
        '#title' => t('Address'),
        '#description' => t('City, State, Contry or zipcode e.g: Dearborn, MI, USA or 48126'),
        '#type' => 'textfield',
        '#default_value' => $address,
        '#required' => TRUE,
      );
      
      
      $form['praytimes_tz'] = array(
        '#title' => t('Time Zone'),
        '#description' => t('Enter the time zone(e.g. Eastern is -5, Central is -6, Mountain is -7 and Pacific is -8).'),
        '#type' => 'textfield',
        '#default_value' => $tz,
        '#required' => TRUE,
      );
        $form['praytimes_month'] = array(
        '#title' => t('Month'),
        '#description' => t('Please enter a month in number form.'),
        '#type' => 'textfield',
        '#default_value' => $cmonth,
      );
        $form['praytimes_year'] = array(
        '#title' => t('Year'),
        '#description' => t('Please enter a Year.'),
        '#type' => 'textfield',
        '#default_value' => $cyear,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      );
    
      return $form;
    }
    
    /**
     * Process a validated Pray Times user setting submission.
     */
    function praytimes_user_settings_form_submit($form, &$form_state) {
      //Rebuild the form.
    
      $form_state['redirect'] = 'prayertimes/timetable';
    
      $address = $form_state['values']['praytimes_address'];
      $tz = $form_state['values']['praytimes_tz'];
      $cmonth = $form_state['values']['praytimes_month'];
      $cyear = $form_state['values']['praytimes_year'];
      $coord = getLatLong($address);
      $lat = $coord['lat'];
      $long = $coord['long'];
       
      
      user_cookie_save(array(
        'praytimes_month' => $cmonth,
        'praytimes_year' => $cyear,
        'praytimes_address'=> $address, 
        'praytimes_tz' => $tz,
        'praytimes_lat' => $lat,
        'praytimes_long' => $long,));
    
      // Notify user.
      drupal_set_message(t('City and Time Zone settings has been saved.'));
    }
    
    function praytimes_table (){
            
        $output = '';
        
        if(!isset($_COOKIE['Drupal_visitor_praytimes_address'])){
            $address = variable_get('praytimes_address');
            $cmonth = variable_get('prayertimes_month');
            $cyear = variable_get('prayertimes_year');
            $tz = variable_get('praytimes_tz');
            $lat = variable_get('praytimes_lat');
            $long = variable_get('praytimes_long');
          }
          else {
            $cmonth = $_COOKIE['Drupal_visitor_praytimes_month'];
            $cyear = $_COOKIE['Drupal_visitor_praytimes_year'];
            $address = $_COOKIE['Drupal_visitor_praytimes_address'];
            $tz = $_COOKIE['Drupal_visitor_praytimes_tz'];
            $lat = $_COOKIE['Drupal_visitor_praytimes_lat'];
            $long = $_COOKIE['Drupal_visitor_praytimes_long'];    
          }
    
        $dst = variable_get('praytimes_dst');
        $today = mktime(0,0,0,$cmonth,1,$cyear);
        $currentmonth = date('F', $today);
        $currentyear = date('Y', $today);
    //  $tempdate = strtotime($currentmonth.'-1-'.$currentyear);
        $tempdate = $today;
        $oneday = 24*60*60

sorry if im confusing cuz im confused as fk as to why this for wouldnt store the values normally and the dude used $_COOKIE


what i want is to store the month/year submitted thru the form to $tempdate and if nothing was submitted to have a default value.