Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Moodle JavaScript Cookbook
Moodle JavaScript Cookbook

Moodle JavaScript Cookbook: Make Moodle e-learning even more dynamic by learning to customize using JavaScript. With over 50 recipes, this Cookbook allows you to add effects, modify forms, include animations, and much more for an enhanced user experience.

eBook
$25.99 $17.99
Print
$43.99
Subscription
$15.99 Monthly

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Apr 26, 2011
Length 180 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849511902
Category :
Table of content icon View table of contents Preview book icon Preview Book

Moodle JavaScript Cookbook

Chapter 1. Combining Moodle and JavaScript

In this chapter, we will cover:

  • Creating a new Moodle PHP page

  • Loading a JavaScript file

  • Loading a JavaScript file in <head>

  • Generating a JavaScript function call from PHP

  • Passing variables from PHP to JavaScript

  • Ensuring compliance with XHTML Strict

  • Retrieving language strings from Moodle

Introduction


Web pages and websites have come a long way since their inception in the early 1990s (with the creation of HTML). Modern web applications such as Moodle now have far more in common with desktop applications than with the simple word processing documents they originally modeled.

One key weapon in the modern web application's armory is the subject of this book — JavaScript.

In essence, JavaScript is a programming language that runs in a user's web browser rather than on the web server. It allows programmers to manipulate the web page via what is called the Document Object Model (DOM). The DOM is a representation of the underlying HTML page, structured in a way to provide access to each and every element within the HTML page. Modern browsers now implement a standard version of the DOM, so it can be considered a cross-platform technology.

In recent years, there has been a significant uptake of the use of JavaScript frameworks. A JavaScript framework is a library of JavaScript code that makes a JavaScript programmer's life easier. Generally, they provide more efficient methods for performing the most common tasks in JavaScript, such as locating DOM elements or wiring up events to those elements. (An event is a function of an element. For example, an HTML input button element has a "click" event that is fired when the mouse is clicked while the pointer is over the button.) Additionally, they provide an abstraction of browser-specific quirks, making it very easy to write cross-platform code that works in the widest range of browsers.

One such JavaScript framework is the Yahoo! User Interface library (YUI). YUI is the framework of choice for Moodle 2.0, and is included with the standard Moodle 2.0 package. For this reason, a substantial number of techniques covered in the later chapters will be based on the YUI. In the final chapter, we will briefly explore some other popular JavaScript frameworks and libraries.

Perhaps more important than "how" to use JavaScript is the question of "when" to use it. It is vital to consider the target audience of your web applications and infer from this exactly how you will use JavaScript.

If you are building a web application that is to be widely used in a public setting, then you should aim to make it as accessible as possible to all types of users. With respect to JavaScript specifically, this means that the core functionality of your site should be available to those who, for whatever reason, cannot or will not use a browser that fully supports JavaScript (typical examples include a mobile device which has limited functionality, or a browser using automated text-to-speech or screen-reading software). These techniques form a part of what is known as "progressive enhancement".

In this first chapter, we will learn the basic techniques for integrating our JavaScript code with Moodle 2.0. We will learn several methods of including our JavaScript code in a Moodle page via .js files, and how to get the code to run. Lastly, we will look at some best practices and also how to make Moodle data and language strings available to our JavaScript code.

Creating a new Moodle PHP page


The code examples used in the recipes throughout this book are all based on the template we will create in this recipe. This template sets up the necessary Moodle environment and displays the standard Moodle header and footer.

This will allow us to look at the generic tools and techniques available to us within Moodle that pertain to JavaScript, allowing you, as the developer, to decide how and where to apply them.

In most instances, it is highly recommended to work with Moodle's rich plugin infrastructure to extend any functionality. This allows you to keep your enhancements completely separate from the core of Moodle, preventing you from introducing bugs into the core code, and making the Moodle upgrade process just a case of ensuring that your particular plugin folders are copied into the upgraded Moodle installation.

Please refer to the Moodle documentation at http://docs.moodle.org/ to decide which plugin framework suits your requirements.

There may be rare cases when it is simply not possible to implement the functionality you desire inside the plugin frameworks, requiring the modification of core code. If this is the case, it is likely that the functionality you desire will be useful to all Moodle users. Therefore, you should look to engage with the Moodle development community to seek advice regarding the feasibility of having your changes included in the next revision of the core code.

If, however, you know for a fact that you definitely need to make changes to core code and that those changes will only be useful to your bespoke use of Moodle, you may consider (as a last resort) modifying the core code files. Be aware that this method is not without issues, incurring significant disadvantages, such as:

  • Keeping track of each change you make to each file, and merging these changes as you upgrade to future versions of Moodle. Version control systems such as CVS or GIT may assist you here.

  • Your changes will not be subject to the same standard of testing and debugging as that of the official core code.

  • Your changes will not be guaranteed to continue to work in future versions; you will need to fully test your changes with each future upgrade.

So, as you can see, there is a trade-off in functionality versus maintainability for each method of extending and enhancing Moodle; so you should choose wisely. If in doubt, use a plugin or theme!

Getting ready

To begin with, we will create a subfolder named cook within our Moodle installation where we will put all the files we will work with throughout the book.

Next we will create the template PHP file blank.php, with the following content:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/cook/blank.php');
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

Note

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

We now have our template saved at /path/to/moodle/cook/blank.php.

To test this new template, we can load it in a web browser and check if all is well. Assuming we have a web server running with Moodle served at the base URL http://localhost/moodle, we can load the following URL to test our new template: http://localhost/moodle/cook/blank.php.

If the template is set up correctly, we will see a basic page with standard header and footer, similar to the following:

How to do it...

We begin by opening the PHP tags in the standard way, using <?php.

Note that we have not used the shorthand notation of <?, as this goes against the Moodle programming guidelines and also against general good practice.

Next, we must include Moodle's global configuration file. The inclusion of this file sets up the requisite Moodle programming environment, including two global variables we will make use of: $PAGE and $OUTPUT.

$PAGE is defined as a central store of information about the current page we are generating in response to the user's request.

The $PAGE object allows us to start defining the properties of the page, namely the context and the URL. The context of the page is the scope of the page, that is, where in the Moodle system it is being used. We are using the System context; other examples are in the Course or Module context.

Next, we set the URL of the page. This mirrors our directory structure; so in this case we just set it to /cook/blank.php.

$OUTPUT is defined as an instance of core_renderer or one of its subclasses. Use it to generate HTML for output.

The $OUTPUT object allows us to generate the header and footer for our page, based on the current Moodle theme. This is done by calling the header and footer methods of the $OUTPUT object, and using echo to write them to the page.

How it works...

After opening the PHP tag, we can begin inserting the PHP code. We use require_once to include the Moodle configuration file (this ensures that the file is included only once, and will halt execution of the page if the file is unavailable). The path to the configuration file is determined by using the dirname function to get the directory path to the current file (using the built-in __FILE__ constant), and then traversing up one directory (as we are in our cook subdirectory) to find the config.php file.

Next, we set the page context by calling the set_context method of the $PAGE object. This takes a context instance. We retrieve the instance for the system context by passing the CONTEXT_SYSTEM constant to the get_context_instance function.

The final usage of the $PAGE object is to set the page URL, which is done using the set_url method, passing in a web root relative URL path, which is /cook/blank.php in this case.

Next, we need to use the $OUTPUT object to generate the header and footer of the page. Both header and footer methods return HTML as a string, so we can use the echo construct to write these strings to the page.

Loading a JavaScript file


A majority of the JavaScript we add will be contained within an external JavaScript file, which is a text file with a .js extension. In this recipe, we will learn how to use the $PAGE object to include such a file.

Getting ready

Make a new PHP file named requirejs.php in the cook directory similar to the template in the previous recipe:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/cook/requirejs.php');
$PAGE->requires->js('/cook/alert.js');
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

Next, we create the accompanying JavaScript file, alert.js, with the following content:

alert('Hello World!');

Now when we load the page in a web browser, we see that the JavaScript alert is displayed as shown in the following screenshot, proving to us that our code has loaded and executed correctly:

Note that we see the Home button, meaning that the footer of the page has loaded. This is because our code is executed at the end of the <body> tag.

How to do it...

We have created a page based on the blank template we created in the first recipe of this chapter. To this, we have added the following line:

$PAGE->requires->js('/cook/alert.js');

How it works...

We are making use of the Page Requirements Manager, $PAGE, which is an object that contains various methods for setting up additional components for a page. Here we have called the $PAGE->requires->js method, and passed the path to our .js file as a parameter.

Moodle then adds this script to the list of scripts to be included within the final rendered page. A <script> tag similar to the following will be inserted just before the closing <body> tag:

<script type="text/javascript" src="http://localhost/moodle/lib/javascript.php? file=%2Fcook%2Falert.js&amp;rev=1"></script>

Note

The <script> tag is inserted at the end of the <body> tag, inline with the current best practice, offering the best page performance and a simplification of handling DOM-ready events among other reasons. For a fuller discussion of this technique, please refer to the Yahoo! Developer Network resource at the following URL:

http://developer.yahoo.com/performance/rules.html#js_bottom

This code must be included after the Moodle configuration file config.php has been included. This is where the $PAGE object is setup for us.

Loading a JavaScript file in <head>


In the previous recipe we learned the standard method of including a JavaScript file at the end of the document's <body> tag.

In this recipe, we will look at how to ensure our JavaScript file is included within the <head> tag. There are numerous reasons why you would require your file be included within the <head>, for example if you need to use document.write to manually write <head> content.

Note

If you are in any doubt, use the technique in the previous recipe. If you need to use the technique in this recipe, the chances are you will know exactly why.

Getting ready

Once again, open the Moodle PHP file where we will add our .js file. We will use the simple example from the previous recipe as a basis, with the necessary changes:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->requires->js('/cook/alert.js', true);
$PAGE->set_url('/cook/requirejs_head.php');
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

Now when we load the page, we see that our JavaScript alert is executed immediately, assuring us that our code is loading and executing correctly, as seen in the following screenshot:

Note that the page underneath is blank at this stage, as our JavaScript code is being run from the <head> tag, before the rest of the page has loaded.

How to do it...

You will notice that this code is almost identical to that of the previous recipe. The key difference here is the parameters we have passed to the $PAGE->requires->js method. We have passed a second optional parameter which determines whether or not the <script> tag will be rendered within the document's <head> tag. In this case, we set it to true to ensure that the <script> tag is rendered as such.

How it works...

We have called $PAGE->requires->js again, this time with two parameters. The first is the path to the .js file we wish to include. The second is a Boolean value which specifies whether or not to include the file from within the <head> tag of the HTML page.

The <script> tag that is rendered to the document is identical to that of the previous recipe, with the crucial difference that it is rendered within the <head> tag, rather than at the end of the <body> tag.

Generating a JavaScript function call from PHP


Now that we have loaded our JavaScript file, we need a method to execute that code. Once again, we may use the Page Requirements Manager $PAGE to generate a call to our JavaScript function.

Note

This recipe describes a basic technique for executing your JavaScript code when the page is loaded. More sophisticated techniques based on handling DOM events with the Yahoo! User Interface library will be covered in later chapters.

Getting ready

Set up a page requirejs_init.php with the following content:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/cook/requirejs_init.php');
$PAGE->requires->js('/cook/requirejs_init.js');
$PAGE->requires->js_init_call('hello');
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

Set up the accompanying JavaScript file, requirejs_init.js, with the following content:

function hello(Y)
{
alert('Hello World!');
}

Now when we load the page, we see that our JavaScript alert is executed, assuring us that our code is loading and executing correctly, as seen in the following screenshot:

How to do it...

We wish to make a call to our JavaScript function named hello. This is achieved with the js_init_call method. We pass one parameter, which is a string containing the name of the function we wish to call, which is hello.

How it works...

When the document is rendered, the js_init_call method ensures that a call to our JavaScript function is generated. This example will generate the following JavaScript:

hello(Y);

This JavaScript is then included inside a <script> tag at the end of the <body> tag of the final page.

Passing variables from PHP to JavaScript


In the previous recipe, we learned how to run our JavaScript function, but we did not pass any data to it. In this recipe, we will pass two parameters to the JavaScript function — a message to be displayed and the current user's username, demonstrating how to make variable values from PHP available within our JavaScript code.

Getting ready

Create a new PHP file requirejs_init_data.php with the following content:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/cook/requirejs_init_data.php');
$PAGE->requires->js('/cook/requirejs_init_data.js');
$PAGE->requires->js_init_call('hello',
array('Hello', $USER->username));
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

This code sets up a simple Moodle page and includes a JavaScript file requirejs_init_data.js containing the following basic "Hello World" function that we will call, which accepts three parameters.

Note that the first parameter Y, which is an instance of the YUI object, is automatically passed to our function by the Page Requirements Manager.

The two subsequent parameters are strings to be passed to the function: message and username:

function hello(Y,message,username)
{
alert(message + ', ' + username);
}

Now when we load the page, we see that our JavaScript alert is executed, displaying the message we passed along with the current user's username (admin):

How to do it...

Just after the call to $PAGE->requires->js, add the following code:

$PAGE->requires->js_init_call('hello', array('Hello', $USER->username));

The first parameter is a string containing the name of the JavaScript function we wish to call, which is hello in this case.

The second parameter is a PHP array of values that are passed on to the JavaScript function in the order in which they are defined.

The use of an array here allows the js_init_call method to support an arbitrary number of arguments, two in this case: the message and username.

How it works...

We have used the Page Requirement Manager to register the name of the function we wish to be called and passed two additional parameters required by the function inside a PHP array.

When the document is rendered, the following JavaScript will be generated inside a <script> tag just before the end of the <body> tag:

hello(Y, "Hello", "admin");

Ensuring compliance with XHTML Strict


Moodle uses the DocType XHTML Strict. We should take care to ensure our JavaScript maintains compliance with this standard.

Although it is best avoided, it may occasionally be necessary to include JavaScript code within <script> tags that are embedded within the page. If this is the case, it is highly likely that the code will include characters that have special meaning to the XHTML Strict specification, for example & and <', '> to name a few.

Getting ready

Open the PHP file that contains the embedded JavaScript and locate the start and end <script> tags.

How to do it...

Add the following code immediately after the opening <script> tag:

<script language="JavaScript" type="text/javascript">
//<![CDATA[

Add the following code immediately before the closing <script> tag:

//]]>
</script>

How it works...

The CDATA tag we have used informs the XHTML rendering engine that it should treat anything inside as arbitrary data, and not to attempt to parse it as if it were valid XHTML markup.

Additionally, to avoid a conflict with JavaScript syntax, the lines on which the CDATA tags reside have been commented out with double forward slashes (//).

Retrieving language strings from Moodle


Moodle makes extensive use of language strings to support full multilingual internationalization. In practice, this means that strings which are used within the interface are held in language-specific files. For example, the string "Submit assignment" may be held in the relevant English language file, and this string may be referred to indirectly via a short name key.

This makes it trivial to support additional languages by creating files for those languages. As the code refers to the strings via their short name keys, it is easy to simply switch the set of language files, and the code will pick up the strings in the new preferred language. This happens automatically when a user changes their preferred language settings.

When providing textual feedback to the user from our JavaScript code, we should make use of Moodle's language string system. This ensures our code is inherently multilingual and makes it easy for a non-developer to provide a language translation of our module.

Getting ready

In this example, we will retrieve the built-in Moodle language string course and show that it is available from our JavaScript code by displaying it with the alert function.

We start once again with a basic Moodle page and associated .js file:

<?php
require_once(dirname(__FILE__) . '/../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/cook/requirejs_init_lang.php');
$PAGE->requires->js('/cook/requirejs_init_lang.js');
$PAGE->requires->string_for_js('course', 'moodle');
$PAGE->requires->js_init_call('lang');
echo $OUTPUT->header();
echo $OUTPUT->footer();
?>

As you can see, this code registers a call to the function lang which has been defined in the associated .js file:

function lang(Y)
{
alert(M.str.moodle.course);
}

Now when we load the page, we see that our JavaScript alert is executed, displaying the language string value we set up, as seen in the following screenshot:

How to do it...

We have included our .js with the method now familiar — $PAGE->requires->js.

After this line comes a new feature of the Page Requirements Manager, the string_for_js function:

$PAGE->requires->string_for_js('course', 'moodle');

Finally, we refer to this language string from our JavaScript code:

alert(M.str.moodle.course);

How it works...

We call the string_for_js method with two parameters: the name of the string we wish to retrieve and the location of this string. In this example, we are retrieving the language string for course from the core Moodle language file.

Now this string is made available to us as part of Moodle's global JavaScript namespace (M) in the format, M.str.<module name>.<string name>. In our example, this is M.str.moodle.course.

Using this method, the strings we have set up will be available to all subsequent JavaScript code. If we had simply passed this string as a parameter to the JavaScript function, it would only be available inside that function. If we required it to be available within additional functions, we would have to repeat the process, making copies of the string and passing those to the additional functions resulting in unnecessarily inefficient code.

Left arrow icon Right arrow icon

Key benefits

  • Learn why, where, and how to add to add JavaScript to your Moodle site
  • Get the most out of Moodle's built-in extra‚Äîthe Yahoo! User Interface Library (YUI)
  • Explore a wide range of modern interactive features, from AJAX to Animation
  • Integrate external libraries like jQuery framework with Moodle

Description

Moodle is the best e-learning solution on the block and is revolutionizing courses on the Web. Using JavaScript in Moodle is very useful to administrators and dynamic developers as it uses built-in libraries to provide the modern and dynamic experience that is expected by web users today.The Moodle JavaScript Cookbook will take you through the basics of combining Moodle with JavaScript and its various libraries and explain how JavaScript can be used along with Moodle. It will explain how to integrate Yahoo! User Interface Library (YUI) with Moodle. YUI will be the main focus of the book, and is the key to implementing modern, dynamic feature-rich interfaces to help your users get a more satisfying and productive Moodle experience. It will enable you to add effects, make forms more responsive, use AJAX and animation, all to create a richer user experience. You will be able to work through a range of YUI features, such as pulling in and displaying information from other websites, enhancing existing UI elements to make users' lives easier, and even how to add animation to your pages for a nice finishing touch.

What you will learn

Get started with the Yahoo! User Interface Library Add validation features to your Moodle forms Retrieve and process data from external sites in a range of formats using AJAX Add feature rich spreadsheet-style data tables—sorting, paging, and inline editing Add auto-complete functionality to text boxes and combo boxes Make use of advanced navigation controls—drop-down menus, tabbed panels, and modal windows Use animation techniques—fading, scrolling, and resizing Integrate external libraries such as JQuery framework, MooTools framework, and Dojo framework Initialize a YUI DataSource

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Apr 26, 2011
Length 180 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849511902
Category :

Table of Contents

15 Chapters
Moodle JavaScript Cookbook Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Combining Moodle and JavaScript Chevron down icon Chevron up icon
Moodle and Yahoo! User Interface Library (YUI) Chevron down icon Chevron up icon
Moodle Forms Validation Chevron down icon Chevron up icon
Manipulating Data with YUI 3 Chevron down icon Chevron up icon
Working with Data Tables Chevron down icon Chevron up icon
Enhancing Page Elements Chevron down icon Chevron up icon
Advanced Layout Techniques Chevron down icon Chevron up icon
Animating Components Chevron down icon Chevron up icon
Integrating External Libraries Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela