I'm having some theming issues and hopefully one of you can set me straight...

I have a custom content type (with CCK fields) that's intended for users to provide a 'conference schedule' -- for example, the user might enter a schedule item such as "9:00am; 9:30am; Registration", or "10:15am; 10:30am; Break", etc. The user may enter as many schedule items as they wish. My intent is to take this input and place it in a 3-column table so it nicely reads: 9:00am - 9:30am Registration, etc. And I've got it working just fine... until the user happens to include a single quote as input.

So, here's what I'm doing:

(1) The field content is first run through check_plain() to ensure safety.
(2) The separate sub-fields (start time, end time, and description) are 'exploded' out into separate variables.
(3) The content is then added to a $row array for use in the theme('table',...) function.
(4) So long as my field doesn't contain apostrophes, things seem to work just as I intend, and the output looks great.
(5) But, once the field contains an apostrophe, the content up to (and including) the single quote is displayed normally, and then everything else in the field is suppressed. (The rest of the table and the remainder of the page appears normally.)

I suspect (incorrectly?) that somewhere deep inside either theme('table',...) or check_plain(), my field content is being interpreted wrong and the apostrophe is screwing things up. Here's the relevant code:

         <?php
         
            $conattributes = array(
               'border'      => 0,
               'cellspacing' => 0,
               'cellpadding' => 5,
               'class'       => 'ConfSchedule'
            );
            $conheader = array(''); // (Blank header)
            $sched     = array();

            foreach ($node->field_schedule as $key => $value) {
               $sched[] = check_plain($value['value']);  // THIS DOESNT WORK
               //$sched[] = $value['value'];  // THIS WORKS
            }

            if (count($sched) > 0) {
               foreach ($sched as $item) {
                  if (!empty($item)) {
                  list($tstart, $tstop, $tdesc) = explode(";", $item);
                  $conrow1  = array(array('data'=>$tstart, 'style'=>'text-align: right;'), '-', array('data'=>$tstop, 'style'=>'text-align: right;'), array('data'=>$tdesc, 'style'=>'padding-left: 4em;'));
                  $conrow[] = array('data'  => $conrow1, 'style' => 'background-color: #FFFFFF;', 'class' => 'ConfSchedule');
                  }
               }
            }
            
            $tableHTML = theme('table', $conheader, $conrow, $conattributes);
            print $tableHTML;
         ?>

Any ideas of how I might fix this? (Thanks for your patience with a theming newbie...)

Comments

milehighlife’s picture

Curious, were you able to resolve this? I'm having the exact same issue--anyone with a last name that has an apostrophe (O'Neil) throws an error on the SQL query.

Thanks!