douqiang1910 2011-01-20 14:41
浏览 51
已采纳

如何在自定义模块中欺骗Drupal 6中的表单值而不会抛出“非法选择”错误

I have a website that uses a View with exposed filters and the Finder module to search for jobs. One of the criteria is salary range, which is displayed in British Pounds in a select box with 4 options. However, the client has asked for an option that allows the user to display a different currency.

I have created a module that allows a user the select a different currency, which in turn sets a session variable containing a currency value. When the user views a page containing either the Finder search form or the Views exposed filter, Drupal adds some JQuery which changes the visible values of the select box based on the value of the session variable. However, it does not change the actual values of the select options - only what the user can see.

Unfortunately this method throws the "illegal choice has been detected please contact the site administrator" error, obviously because the posted form array doesn't match the form array stored by Drupal. So the question is, how can I stop this error from occurring? I was thinking of the form values being reset by JQuery just before submit, although I'm not sure how I would change the values between the user clicking the submit button and the form actually being submitted. Another choice is perhaps hook_form_alter to change the form values, but I'm not exactly sure if this would work either.

Any ideas?

  • 写回答

1条回答 默认 最新

  • donglan8999 2011-01-21 11:17
    关注

    Just for anyone that was interested, I created a new module that uses hook_form_alter. The hook adds an extra button for currency and when submitted, sets a session variable containing the currency information. When my module reads the session, it alters the actual salary band field based on the session value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog