0

in mt .tp file I have a loop that outputs Publish or something similar for each entry. I don't want it to refresh the page when clicking on the so I want to call some json instead to call a module and pass some parameters to update the Database but I am not sure how to go about it. Do I need a new module with something like this in it?

function menudemo_menu() {

    $menuitems['menudemo'] = array(

    'title' => 'My Menu',

    'page callback' => 'menudemo_mymenu_page_callback',

    'access callback' => TRUE,

    'type' => MENU_CALLBACK,

    );

    return $menuitems;

}

function menudemo_mymenu_page_callback() {

    return 'My Menu URL was hit';

}

And how do I pass the parameters

5
  • Are you trying to reload some part of your page with an AJAX Callback ?
    – pbonnefoi
    Commented Feb 11, 2016 at 10:53
  • I just want to click on the <a> in <div><a class="button" href="">Publish</a></div> to update the Database and the contents of the div will then change to say it has been done. The div will need an id so the json can write to it Commented Feb 11, 2016 at 11:08
  • From what I understand it's a Callback AJAX to publish content without reloading the page. You'll have to either trigger an event in JS to callback your hook_menu that will update the database or user a button and the AJAX Form API => api.drupal.org/api/drupal/…
    – pbonnefoi
    Commented Feb 11, 2016 at 11:27
  • Yep it is. Good it sounds as though I am going the right way about it then - thanks Commented Feb 11, 2016 at 12:02
  • Here is a nice example: phpgainers.com/content/… Commented Feb 11, 2016 at 12:51

1 Answer 1

0

Thanks for the confirmation - I was on the right track. I just need to add in the sql update command now and will all be working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.