This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

When I was creating the Global Areas block I needed the cID to be passed to a function when a page was chosen, but I ran into a bunch of problems when trying to get it to work.

A page selector with no callback looks like this:

<?php echo Loader::helper('form/page_selector')->selectPage('targetCID', $targetCID); ?>

where the field name is targetCID and if $targetCID is set that is the value.

The page selector has a 3rd parameter which is the javascript callback:

<?php echo Loader::helper('form/page_selector')->selectPage('targetCID', $targetCID, 'pschange'); ?>

Where pschange is the name of the javascript function.

When you change the callback from the default, you have to manually edit the value in the html, otherwise the page selector will do nothing. For example:

pschange = function(cID, cName) {
    /* preform the basic html changing of the page selector */  
    $('input#[name=\'targetCID\']').val(cID);
    $('.ccm-summary-selected-item-inner').html('<strong class="ccm-summary-selected-item-label">' + cName + '</strong>');
}

You have to change 'targetCID' to whatever the name is (as used in the php for the page selector).

After that code, you can add whatever javascript code you want, like:

alert('Name: ' + cName);
alert('CID: ' + cID);

Which will show alert windows with the data.

I wanted to run the function with the preset data right on page load ($targetCID is set) so at the end of the code I added this:

<?php if($targetCID) { ?>
    <script type="text/javascript">
        $(document).ready(function() {
           pachange('<?php echo $targetCID?>', '<?php echo $name?>');
         });
    </script>
<?php } ?>

Where $targetCID is the cID (1) and $name is the Page name (Home) To get the name I used this simple code: $name = Page::getByID($targetCID);

And that is how to have a custom callback for the page selector

To checkout the full code checkout the edit.php in the Global Areas Block.

Loading Conversation