Problem passing a date to a record using $addLink and an email template

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 27, 2017   (RSS)

Hi All,

I’ve been using a series of $addLinks together with an email template to develop a link that’s emailed to the admin which will create a record in my 'around_town' database, (see the old post at https://www.interactivetools.com/forum/forum-posts.php?postNum=2240565 ) and it’s working fine for text fields.

I’m having trouble passing a date to a date field in the database and could use some guidance.

Here’s the active code I’m using (extra field code removed):
Before the head:

$band =  $_REQUEST['band_name'];
 $date = date("Y-m-d",mktime(0,0,0,@$_REQUEST['month_1'],@$_REQUEST['day_1'],@$_REQUEST['year_1']));

if (!$errorsAndAlerts) {

 $addLink  = "http://my_site.com/cmsAdmin/admin.php?menu=around_town&action=add";
$addLink .= "&band_name=" .urlencode(@$_REQUEST['band_name']);
$addLink .= "&event_date="    .urlencode($date);
     // send email to Admin
          $emailHeaders = emailTemplate_loadFromDB(array(
    'template_id'  => 'EVENT-LISTING-REQUEST',
    
    'placeholders' => array(
      'band_name'     =>  ($_REQUEST['band_name']),
      'date'     =>  ($date),
      'addLink'   => $addLink,
           )));
      $mailErrors   = sendMessage($emailHeaders);
      if ($mailErrors) { alert("Mail Error: $mailErrors"); }

And the Form:

<form method="post" action="">
                <input type="hidden" name="save" value="1" />
                <table border="0" cellspacing="0" cellpadding="2">
<tr>
                    <td width="40%" align="left" valign="middle" class="text_font"><b>Musician or  Band Name</b></td>
                    <td style="text-align:left" align="left" valign="middle"><input class="text" type="text" name="band_name" id="band_name" value="<?php echo htmlencode(@$_REQUEST['band_name']); ?>" /></td>
                  </tr>
                  <tr>
     <td width="40%" align="left" valign="middle" class="text_font" ><b>First Event Date<br />
                      </b></td>
     <td><?php  
$lowestYear  = date("Y");  
$highestYear = date('Y', strtotime('+1 years'));  
?>
Month:  
<select name="month_1" id="month1">  
  <?php foreach(range(1,12) as $month_1): ?>     
    <option value="<?php echo $month_1;?>"><?php echo date("F",strtotime("0000-$month_1"));?></option>  
  <?php endforeach ?>  
</select> Day:  
<select name="day_1" id="day1">  
  <?php foreach(range(1,31)as $day_1): ?>  
      <option value="<?php echo $day_1;?>"><?php echo $day_1;?></option>    
  <?php endforeach ?>  
</select> Year:  
<select name="year_1" id="year1">  
   <?php foreach (range($lowestYear,$highestYear) as $year_1):?>  
       <option value="<?php echo $year_1;?>"><?php echo $year_1;?></option>  
   <?php endforeach?>  
</select>

   </tr>
<tr>
<td colspan="2" align="center"><br/>
<input class="button" type="submit" name="submit" value="SUBMIT YOUR LISTING REQUEST &gt;&gt;" /></td>
 </tr>
</table>
</form>

The $date value is shown correctly in the email template and the email, and the link produced is:

http://my_site.com/cmsAdmin/admin.php?menu=around_town&action=add&band_name=Joe+Jones&event_date=2018-04-04

All other (text) fields are added to the database record correctly , however, the ‘event_date’ date field remains blank.

Thanks for looking at this.

Jerry Kornbluth

 

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - October 27, 2017

Hi Jerry, 

Passing in field values via the url isn't an official feature, and might trigger "indirect links" warnings (unless you turn that off).  But the reason it's not working is because it's not supported on date fields.  Try this patch: 

In /lib/menus/default/edit_functions.php search for: get date value

And replace this:

// get date value(s)
$dateValue  = @$record[$fieldSchema['name']] ? $record[$fieldSchema['name']] : $defaultDateTime;

With this: 

// get date value(s)
$fieldname = $fieldSchema['name'];
if     (isset($record[$fieldname]))   { $dateValue = $record[$fieldname]; }
elseif (isset($_REQUEST[$fieldname])) { $dateValue = $_REQUEST[ $fieldname ]; }
else                                  { $dateValue = $defaultDateTime; }

Let me know if that works for you and I'll add it to the next release.

Dave Edis - Senior Developer
interactivetools.com

Afternoon Dave,

Thanks for this.

I'm passing the values:

http://mysite.com/cmsAdmin/admin.php?menu=my_table&action=add&event_date=2018-06-16 (and other field parameters)

and your suggestion does work, but it throws the following errors:

Notice: Undefined offset: 1 in /home3/ellescho/public_html/jazzonjstreet/cmsAdmin/lib/menus/default/edit_functions.php on line 351 Notice: Undefined offset: 2 in /home3/ellescho/public_html/jazzonjstreet/cmsAdmin/lib/menus/default/edit_functions.php on line 353 Notice: Undefined offset: 1 in /home3/ellescho/public_html/jazzonjstreet/cmsAdmin/lib/menus/default/edit_functions.php on line 353

and it does throw an 'indirect link' warning as well, but I can live with that one.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - October 27, 2017

Can you try adding @ in front of the list(): 

    @list($date,$time)       = explode(' ', $dateValue); // expecting: YYYY-MM-DD HH:MM:SS
    @list($year,$month,$day) = explode('-', $date);      // expecting: YYYY-MM-DD
    @list($hour24,$min,$sec) = explode(':', $time);      // expecting: HH:MM:SS

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com