关于向drupal中添加js的问题

liangpei2008 2009-08-07 06:43:08

//请问大家有熟悉drupal的吗?我想在user.module中的user_authenticate函数中插入一段script,请问如何做?
function user_authenticate($name, $pass) {
global $user;
// Try to log in the user locally. Don't set $user unless successful.
if ($account = user_load(array('name' => $name, 'pass' => $pass, 'status' => 1))) {
// Check if the e-mail is denied by an access rule.
// Doing this check here saves us a user_load() in user_login_validate()
// and introduces less code change for a security fix.
if (drupal_is_denied('mail', $account->mail)) {
form_set_error('name', t('The name %name is registered using a reserved e-mail address and therefore could not be logged in.', array('%name' => $account->name)));
return;
}
else {
//我想在登陆成功后在这里插入一段script,请问如何插入,试了一个晚上,用drupal_add_js总是不行

$user = $account;

return $user;
}
}
...全文
400 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
coder_up 2012-08-13
  • 打赏
  • 举报
回复
drupal_add_js(drupal_get_path('theme','XXX')."/js/XXX.js");
linglingnie 2009-08-07
  • 打赏
  • 举报
回复
那这样呢
else {
?>
<script type='javascript'> alert("要显示的js!"); </script>
<?
$user = $account;
dzxccsu 2009-08-07
  • 打赏
  • 举报
回复
那考虑用层来做提示吧!
<div id=""> echo "这里插入提示之类语言!";</div>
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
没有,真是郁闷至极啊
dzxccsu 2009-08-07
  • 打赏
  • 举报
回复
加了JS后,面页有没有说面页有错误之类的东东?
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
在user.module中使用Echo script后,在用户登陆后,则变成第一屏是白屏,再刷一次,才能到正常页面
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
是的,我跟踪过,代码是能执行到的
dzxccsu 2009-08-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liangpei2008 的回复:]
引用 4 楼 dzxccsu 的回复:
你要插入什么JS?
echo ' <script type=javascript> alert("插入东西拉!"); </script>';

我以前就是这么写的,但在user.module中使用echo是不行的,所以才来问的
[/Quote]执行这段代码的条件是否符号呢?
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dzxccsu 的回复:]
你要插入什么JS?
echo ' <script type=javascript> alert("插入东西拉!"); </script>';
[/Quote]
我以前就是这么写的,但在user.module中使用echo是不行的,所以才来问的
dzxccsu 2009-08-07
  • 打赏
  • 举报
回复
你要插入什么JS?
echo '<script type=javascript> alert("插入东西拉!");</script>';
残剑无弦 2009-08-07
  • 打赏
  • 举报
回复
楼主真逗!~

PHP是服务器语言 JS是客户端语言 怎可同日而语?
除非你将JS设置成Server 或者 在PHP中用上echo('<script type=javascript></script>');输出到客户端运行
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
up
liangpei2008 2009-08-07
  • 打赏
  • 举报
回复
哪位老兄能告诉我,另有500分回报
xubaoguo196 2009-08-07
  • 打赏
  • 举报
回复
请问楼主的qq是多少啊告诉我
phpboy 2009-08-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liangpei2008 的回复:]
引用 4 楼 dzxccsu 的回复:
你要插入什么JS?
echo ' <script type=javascript> alert("插入东西拉!"); </script>';

我以前就是这么写的,但在user.module中使用echo是不行的,所以才来问的
[/Quote]

return 的是 $user 和 之前 用一句 echo ' <script type=javascript> alert("插入东西拉!"); </script>'; 应该没有什么关系

或者是 return 后,进行 判断

if (user_authenticate($name, $pass)) {
//...
cho ' <script type=javascript> alert("插入东西拉!"); </script>';
} else {
//..
}
ruanchao 2009-08-07
  • 打赏
  • 举报
回复
drupal在国内的普及度本来就不高,何不到drupal.org的论坛去问问呢?
ruanchao 2009-08-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 liangpei2008 的回复:]
在user.module中使用Echo script后,在用户登陆后,则变成第一屏是白屏,再刷一次,才能到正常页面
[/Quote]

你用echo有输出,而且输出为空,当然就为空了。

drupal有专门的调用js的函数drupal_add_js, 你为何不用呢?
Drupal 6 JavaScript and JQuery By Matt Butcher Publisher: Packt Publishing Limited 2009 | 340 Pages | ISBN: 1847196160 | PDF | 3 MB Putting jQuery, AJAX, and JavaScript effects into your Drupal 6 modules and themes Learn about JavaScript support in Drupal 6 Packed with example code ready for you to use Harness the popular jQuery library to enhance your Drupal sites Make the most of Drupal's built-in JavaScript libraries In Detail JavaScript: It's not just for calculators and image rollovers. Drupal 6 is loaded with new features, and not all of them are necessarily implemented in PHP. This unique book, for web designers and developers, will take you through what can be done with JavaScript (and especially with jQuery) in Drupal 6. With the combination of the powerhouse jQuery library with its own robust set of JavaScript tools, Drupal 6 comes with a pre-packaged killer JavaScript environment. Cross-platform by nature, it provides all of the tools necessary to create powerful AJAX-enabled scripts, gorgeous visual effects, and view-enhancing behaviors. In addition, Drupal developers have ported some of its most powerful PHP tools - like a theming engine and support for localization and language translation - to JavaScript, making it possible to write simple scripts where once only complex PHP code could be used. This book gives you the keys to the toolbox, showing you how to use Drupal's JavaScript libraries to make your modules and themes more dynamic, interactive and responsive, and add effects to make your Drupal site explode into life! If you've dipped your toe in the water of theme or module development with Drupal 6, this is the book you want to make the look and behavior of your work something special. With it's project-based approach, this book is carefully constructed to guide you from how JavaScript fits into the overall Drupal architecture through to making you a master of the jQuery library in the world of Drupal themes and modules. What you will learn from this book? An introduction to JavaScript in Drupal 6 The basics of the jQuery library Creating JavaScript-enabled themes Manipulating a page on the fly with jQuery Authoring simple PHPTemplate files designed to maximize scripting potential Using jQuery to add effects in Drupal 6 Working with Drupal 6 behaviors Adding AJAX to modules Using Drupal's localization and language translation engine in your JavaScript Theming on the client-side with Drupal's JavaScript theme engine Building better forms Working with Drupal 6's JavaScript library Writing portable JavaScript tools as Drupal modules Approach This book focuses on teaching by example. Chapters are packed with example code, providing hands-on examples you can play with and then release to your own Drupal sites. By introducing short projects interspersed with discussion, the pace is rapid yet practical. Who this book is written for? This book is for web designers and developers who want to add JavaScript elements to Drupal themes or modules to create more flexible and responsive user interfaces. You are expected to know about the basic operation of Drupal, and be familiar with the concept of theming and modules in Drupal. No experience of creating themes or modules is required. You will need to know the basics of client-side web development; this means HTML, CSS, but also have a rudimentary grasp of the syntax of JavaScript. Familiarity with PHP programming will be an advantage, since we will be writing PHPTemplate files and (at the end) creating Drupal modules. However, the PHP is covered thoroughly enough that even the PHP neophyte will not find the text too demanding. The book also covers the jQuery JavaScript library and its use in Drupal, but no knowledge of jQuery is expected - you will learn everything you need in this book. About the Author Matt Butcher is a senior programmer at Palantir.net, where he specializes in content management systems, web services, and browser scripting. He has been an active participant in Open Source technologies for over a decade. Matt has written five books for Packt, including Learning Drupal 6 Module Development, Mastering OpenLDAP, and Drupal 6 JavaScript and jQuery., all of which are published by Packt. Matt writes his technical blog at technosophos.com. When not pushing bits, Matt likes to explore Chicago with his wife and three daughters.

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧