Sunday, October 7, 2012

How to construct link to edit single zoo record


I'm writing this post because its quite tricky to create a link which edits a zoo record based on zoo item id unless you know how exactly zoo construct hashes.
When we asked on zoo forum they didn't reply with the following solution. I must admit that zoo component is excellent but their support is very poor & you know zoo support is paid! Okay leave it & lets move to the link.
Stop thinking that I'll pass zoo id to the zoo's my submission menu link to create edit record link. What?? have you tried it?? Does it says Hashes did not match. Alright Don't worry you are the right place.
Its very easy, you just need to pass submission type of zoo item & zoo item id itself to the getSubmissionHash API which returns you respective hash for the item.

$zapp = App::getInstance('zoo');
$items = $zapp->table->item->all(array('conditions' => 'id =$zoo_item_id)); 
//$zoo_item_id must be zoo record id which you want to edit.
$type = $items[$item->id]->type;
// get submission type of item
$hashRelated = $zapp->submission->getSubmissionHash(1,$type, $item->id); 
 // Here is the exact hash for the record

$href = JRoute::_(JURI::Base()."index.php?option=com_zoo&view=submission&layout=submission&submission_id=1&type_id=$type&item_id=$item->id&submission_hash=$hashRelated"); // Construct link as zoo 

echo '<a href=".$href.">Edit Record</a>';

12 comments:

  1. Hi, I have a Joomla site and I create a submission page for public to submit their details. However the page gives me the error "Hashes did not match." and I have no idea how to fix the issue. I did not make any changes or write any php script for the submission page. Can you assist me? The URL is at http://tuitiongiving.com/request.

    ReplyDelete
  2. Hi Royce, Are you using Zoo component?? I guess you are not. Tell me a bit more about how your are constructing this link. Is it Joomla article or any other extension.

    ReplyDelete
  3. Hi,

    I am using zoo component for the submission. I create the submission from the joomla backend in the zoo component and assigning some of the elements to the form. Then I add a new menu item for this submission which is the link in my previous comment.

    Maybe for more information, I actually have a development site at http://test.itutor.sg and the submission page works there (http://test.itutor.sg/request). However, when I use the akeeba backup and restore using kickstart to this new domain (tuitiongiving.com), that page gave me that error "Hashes did not match."

    I not sure what went wrong. Thanks a lot for your reply! :)

    ReplyDelete
  4. I don't understand. Where do I put this? Kindly reply. Thanks

    ReplyDelete
  5. What u didn't understand, pls tell me. How you tried????

    ReplyDelete
  6. First of all, thanks for the super prompt reply.. Here's my problem, whenever i use Zoo frontend submission I get error 'Hashes did not match'. I unpublished recaptcha plugin thinking that was the problem but it still doesn't work. I'm fairly intermediate in coding so I'm struggling to understand where I'm supposed to add the code u used above.. Kindly help. Thanks

    ReplyDelete
  7. I'm on Joomla 2.5.9

    ReplyDelete
  8. How get submission ID?

    ReplyDelete
  9. 'Hashes did not match' - if you have few submissions, and Item not for this submission, e.q. 1
    Need get submission ID, and put in string
    $hashRelated = $zapp->submission->getSubmissionHash( here need right submissionID,$type, $item->id);
    and here
    $href = JRoute: ..... submission_id=put here rught submission ID ...

    ReplyDelete
  10. $app_id = $items[$item->id]->application_id;
    $app_id will contains the application id. :)

    ReplyDelete
  11. application_id its not submission ID. In one application I can create multiple submission and each will have its own id.

    ReplyDelete