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.