Forums / Setting Up Categories, Products, Attributes / Losing field value in new product type

Losing field value in new product type

Started by ricm on 16 May 2011, 7:57 PM · Views: 887

Results 1 to 2 of 2
16 May 2011, 7:57 PM
#1
ricm avatar

ricm

New Zenner

Join Date:
Mar 2011
Posts:
51
Plugin Contributions:
0

Losing field value in new product type

Hi,

I have a new product type for photos. Almost everything is working apart from a description field in the admin area when adding or editing a product.

The new field is image_sizes_name and is one of 4 fields in a new table "product_photo_extra". 3 fields are lookups, the 4th is free-form text to be edited in an instance of the FCKeditor.

If I pre-populate the table field the editor correctly retrieves the value (function zen_get_image_sizes is working). However after preview --> update the value for the text field is lost (it shows as 0); the values of the other three fields are stored.

The fact that the other three values are updated suggest the update is working correctly. For this one field either the value isn't being read from the editor or the value isn't being passed when it comes to the update.

The code surrounding the editor in collect_info.php is:

<!-- image_sizes new code start --> <?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) { ?>
      <tr>
        <td class="main" valign="top"><?php if ($i == 0) echo TEXT_PRODUCTS_IMAGE_SIZES; ?></td>
        <td colspan="2">
    <table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td class="main" width="25" valign="top"><?php echo zen_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?> </td>
              <td class="main" width="100%">
                <?php if ($_SESSION['html_editor_preference_status']=="FCKEDITOR") {
                   $oFCKeditor = new FCKeditor('image_sizes_name[' . $languages[$i]['id'] . ']') ;
                   $oFCKeditor->Value = (isset($image_sizes_name[$languages[$i]['id']])) ? stripslashes($image_sizes_name[$languages[$i]['id']]) : zen_get_image_sizes($pInfo->products_id, $languages[$i]['id']);
                   $oFCKeditor->Width  = '99%' ;
                   $oFCKeditor->Height = '350' ;

// $oFCKeditor->Config['ToolbarLocation'] = 'Out:xToolbar' ;
// $oFCKeditor->Create() ;
$output = $oFCKeditor->CreateHtml() ; echo $output;
} else { // using HTMLAREA or just raw "source"

                  echo zen_draw_textarea_field('image_sizes_name[' . $languages[$i]['id'] . ']', 'soft', '100%', '30', (isset($image_sizes_name[$languages[$i]['id']])) ? htmlspecialchars(stripslashes($image_sizes_name[$languages[$i]['id']]), ENT_COMPAT, CHARSET, TRUE) : htmlspecialchars(zen_get_image_sizes($pInfo->products_id, $languages[$i]['id']), ENT_COMPAT, CHARSET, TRUE)); //,'id="'.'image_sizes_name' . $languages[$i]['id'] . '"');
                } ?>
             </td>
          </tr>
        </table>
 </td>
      </tr>
<?php } ?> <!-- image_sizes new code end -->

The relevant bit of code in update_product.php is:

$tmp_value = zen_db_prepare_input($_POST['photographers_id']);
$photographers_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$tmp_value = zen_db_prepare_input($_POST['model_release_id']);
$model_release_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$tmp_value = zen_db_prepare_input($_POST['property_release_id']);
$property_release_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$tmp_value = zen_db_prepare_input($_POST['image_sizes_name']);
$image_sizes_name = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;

  $sql_data_array = array('photographers_id' => $photographers_id,
                          'model_release_id' => $model_release_id,
                          'property_release_id' => $property_release_id,
  	      'image_sizes_name' => $image_sizes_name );

  zen_db_perform(TABLE_PRODUCT_PHOTO_EXTRA, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");

Any and all suggestions greatly appreciated.
Ric

16 Mar 2012, 11:50 PM
#2
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Losing field value in new product type

Kind of old but for anyone else:

in update_product.php

$sql_data_array = array(
'photographers_id' => $photographers_id,
                              'model_release_id' => $model_release_id,
                              'property_release_id' => $property_release_id,
			      'image_sizes_name' => $image_sizes_name );

should be:

$sql_data_array = array(
'photographers_id' => zen_db_prepare_input($_POST['photographers_id']),
                               'model_release_id' => zen_db_prepare_input($_POST['model_release_id']),
                               'property_release_id' => zen_db_prepare_input($_POST['property_release_id']),
 			      'image_sizes_name' => zen_db_prepare_input($_POST['image_sizes_name']),