Forum

Thread tagged as: Question, Problem

perch_content_create problem

Can you spot why the following code works fine on a Perch V2.8 site but outputs no html at all on 3.0.10 site?

      <?php

     perch_content_create('Horses', array(
     'page' => '/horses2.php',
          'template'  => 'horse_product_detail.html',
          'multiple'  => true,
          'edit-mode' => 'listdetail',
     ));


     if (perch_get('s')) {

          // Detail mode
          $result = perch_content_custom('Horses', array(

               'template' => 'horse_product_detail.html',
               'filter'   => 'slug',
               'match'    => 'eq',
               'value'    => perch_get('s'),
               'count'    => 1,
               'skip-template' => true,
               'return-html'   => true,
          )); 
echo $result['html'];
perch_content_custom('Horses', array(
    'template'   => 'product_prevnext.html',
    'filter'     => '_order',
    'match'      => 'gt',
    'value'      => $result[0]['_sortvalue'],
    'sort'       => '_order',
    'sort-order' => 'ASC',
    'count'      => 1,
));
PerchSystem::set_var('is_prev', true);

perch_content_custom('Horses', array(
    'template'   => 'product_prevnext.html',
    'filter'     => '_order',
    'match'      => 'lt',
    'value'      => $result[0]['_sortvalue'],
    'sort'       => '_order',
    'sort-order' => 'DESC',
    'count'      => 1,
));
     } else {

          // List mode
          perch_content_custom('Horses', array(
          'page' => '/horses2.php',
               'template' => 'horse_product_listing.html',
                'sort' => 'title',
          )); 
     }

?>

Debug says


Debug Message - Perch 3.0.10 [31] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0 [3] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/horses2.php' OR regionPage='*' ORDER BY regionPage DESC [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch3_content_regions WHERE regionKey='Horses' AND (regionPage='horses2.php' OR regionPage='*') [nil] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='title' WHERE ((idx.regionID=5 AND idx.itemRev=22)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY sortval ASC Using template: /templates/content/horse_product_listing.html
Charlie Elsey

Charlie Elsey 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do the two share the same data?

No shared data. Templates etc and type of data is similar for two clients with same requirements. System works great for 'older' client (on v2.8). Newer client I used latest V3 but really that is the only difference.

From debug in perch edit area, is this the problem? 'Form not posted or did not validate' After editing, admin tells me content updated correctly. Using template horse_product_detail.html shown below debug


Debug Message - Perch 3.0.10 [1] SELECT u.*, r.* FROM perch3_users u, perch3_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='f497aea46dc1b69bf696b2a6189c844b' LIMIT 1 UPDATE perch3_users SET userHash='181de4b3cac2a986d02aeae11760f216' WHERE userID='1' [31] SELECT settingID, settingValue, userID FROM perch3_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC [8] SELECT itemValue FROM perch3_menu_items WHERE itemType='app' [1] SELECT * FROM perch3_content_regions WHERE regionID=5 LIMIT 1 [1] SELECT * FROM perch3_pages WHERE pageID='2' LIMIT 1 Using template: /templates/content/horse_product_detail.html [1] SELECT * FROM perch3_content_items c WHERE c.regionID=5 AND c.itemRev=33 AND c.itemID=11 ORDER BY c.itemOrder ASC Using template: /templates/content/horse_product_detail.html Form not posted or did not validate [1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1 [3] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC [1] SELECT itemTitle FROM perch3_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1 [1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10 [2] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC File: /core/apps/content/modes/edit.form.post.php Mode: edit.form Queries: 13 Memory: 5.2827

template in question

    <div class="column-content">
      <h1>
        <perch:content id="horse_name" type="text" label="Horse name" required="true" title="true" />
      </h1>
      <perch:content id="horse_image1" type="image" label="Image 1" class="scalable" width="640" output="tag" />
      <p class="bolditalic">
        <perch:content id="horse_foal_year" type="text" label="Year of foaling" required="true"  />
         
        <perch:content id="horse_colour" type="radio" label="Colour" options="Bay, Bay/Brown, Black, Brown, Chesnut, Grey, Roan" html="false" required="false" title="false" />
         
        <perch:content id="horse_sex" type="radio" label="Sex" options="Colt, Horse, Gelding, Filly, Mare" html="false" required="false" title="false" />
        <br />
        by
        <perch:content id="horse_sire" type="text" label="Sire" html="false" required="false" title="false" />
         ex 
        <perch:content id="horse_dam" type="text" label="Dam" html="false" required="false" title="false" />
         (
        <perch:content id="horse_damsire" type="text" label="Dam sire" html="false" required="false" title="false" />
        ) </p>
      <h2>
        <perch:if exists="silks"><img src="<perch:content type="image" id="silks" label="Owners colours or silks" width="110" />" class="scalable fltrt" alt="
          <perch:content id="horse_vendor" label="Owner" type="text"   />
          " />
          <perch:else />
        </perch:if>
        Owner: 
        <perch:content id="horse_vendor" type="text" label="Owner" html="false" required="false"  />
      </h2>
      <perch:content id="desc" type="textarea"  editor="redactor" label="Notes about this horse" html="true" size="s" />
      <perch:if exists="horse_racerecord"> <a href="https://www.racingpost.com/horses/horse_home.sd?horse_id=<perch:content id="horse_racerecord" type="text" label="Racing post ID number"  /> " target="_blank">
        <p>
          <perch:content id="horse_name" type="text" label="Horse name"  />
          's racing form, courtesy Racing Post</p>
        </a>
        <perch:else />
      </perch:if>
      <perch:if exists="horse_file"> <a href="<perch:content id="horse_file" type="file" label="Pedigree File"  /> " target="_blank">
        <p>Pedigree file download</p>
        </a>
        <perch:else />
      </perch:if>
      <perch:content id="slug" for="title" type="slug" suppress="true" />
      <perch:content id="horse_image1" type="image" label="Image"  width="150" height="100" crop="true" suppress="true" />
    </div>
  </div>
  <div class="column-half">
    <div class="column-content">
      <p class="bolditalic red">
        <perch:if exists="saleitem">
          <perch:content id="saleitem" type="select" label="Leave blank OR CHOOSE option" options="For sale, Shares available, Sale consignment" allowempty="true" required="false"  />
          <perch:else />
        </perch:if>
      </p>
      <perch:if exists="saleprice">
        <p>Price: £
          <perch:content id="saleprice" type="text" label="Price"  />
        </p>
        <perch:else />
      </perch:if>
      <perch:if exists="salenotes">
        <p>
          <perch:content id="salenotes" type="textarea"  editor="redactor" label="Sale notes" html="true" size="s"  />
        </p>
        <perch:else />
      </perch:if>
      <perch:if exists="horse_video1">
        <div class="embed-container">
          <iframe width="480" height="270" src="https://www.youtube.com/embed/<perch:content id="horse_video1" type="text" label="Youtube video code"  />
          ?rel=0&controls=0&showinfo=0" frameborder="0" >
          </iframe>
        </div>
        <perch:else />
          </perch:if>
    </div>

Drew McLellan

Drew McLellan 2638 points
Perch Support

The two should work in the same way.

Drew McLellan said:

The two should work in the same way.

and yet they do not! Nothing jumps out at you from debug then, that looks 'normal'?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, it looks fine to me. What are you attempting to do here? Why do you need the same code to work with two versions?

two different clients, two different websites, sharing same need for display of similar data. First client still on V2 perch, new client on V3 perch. think I will go back to v2 for new client too maybe.

SOLVED, found errant code, sorting on wrong field

Sorry for wild goose chase Drew you can mark this as solved and get on with some real problems