Drupal 7 – Simple Ajax implementation @ 3

In the past 2 days we have developed a custom module which demonstrates the basic Ajax implementation in Drupal 7.

 

Today i will continue the example written by Kevin Hankens and make the module more secure. We want to add a token in the Ajax request such that the server could check if it comes from a valid user. This token could be obtained from drupal_get_token() which will return a fixed token value for each user session. Here are the list of changes in the new eureka_ajax.module.

  • Set the token value in Drupal.settings in hook_init()
  • Add the token as query string in the theme_ajax_link()
  • Check if the token is valid in ajax_request_callback()

Continue reading Drupal 7 – Simple Ajax implementation @ 3

Drupal 7 – Simple Ajax implementation @ 2

I will continue the Ajax example which we did in
Drupal 7 – Simple Ajax implementation @ 1

So this time we will add some access control on the above example. In Drupal 7 & 8 development, we could create new permissions by implementing the hook_permission(). After that we could modify the access arguments in the hook_menu().
Continue reading Drupal 7 – Simple Ajax implementation @ 2

Drupal 7 – Simple Ajax implementation @ 1

In this post, i will show you how to implement a simple Ajax function in Drupal 7. The following example code is based on the blog post written by Kevin Hankens about implementing Ajax in Drupal 6.
Kevin Hankens’s blog – Drupal, jQuery and $.ajax() easyness

What i am going to do is the same as Kevin’s example. But for simplicity, i removed the access control logic so all content is visible to anonymous users.
Continue reading Drupal 7 – Simple Ajax implementation @ 1

陶傑 – 他已經上了你

梁特首沒上任,先爆連串政治大麻煩,家居六處僭建,香港譁然,此一危機很嚴重。

人家僭建,你昂首挺胸說他是「誠信」問題。三個月的密集炮火下來,好,原來自己也僭建,說只是「無心之失」的疏忽,普世沒有這樣的道理。

但候任特首是中國人。中國人的是非邏輯一向都非常有趣:什麼是「誠信問題」,什麼是「疏忽」,完全視權力分布而定。譬如:一個小百姓反抗,殺了個公安,「訂一個說法」,是殺人兇手,但毛×東殺人接近一億,卻是「犯了錯誤」。

我請教過來自大陸崇拜毛澤東的許多中國人,如果毛主席犯了「錯誤」,希特拉何嘗不是一點點「錯誤」?他們說:毛主席不同,要全面評價一個人物;毛澤東思想為中國人民謀了巨大的幸福,毛主席把帝國主義趕出中國,對比之下,殺那麼個把千萬人,算不得什麼,人民願意付出代價。
Continue reading 陶傑 – 他已經上了你

Drupal 7 – Legal module error – Notice: Undefined variable: accepted in legal_form_user_profile_form_alter()

The stable release of the Legal module has so many errors. But this one is also found in the dev release.

This error this time is
Notice: Undefined variable: accepted in legal_form_user_profile_form_alter()…
Continue reading Drupal 7 – Legal module error – Notice: Undefined variable: accepted in legal_form_user_profile_form_alter()

Drupal 7 – Legal module error – array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()

If you meet the following error of the Legal module.
Notice: Undefined variable: options in views_handler_field_locale_language->render()…
 
Continue reading Drupal 7 – Legal module error – array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()

Dream BIG and go for it =)