Drupal Form API

Now, form generation engine collects the information about formelements bycalling<wbr><em>element_info()</em><wbr>function.This in turn calls<em>hook_element()</em>, which might beimplemented by other modules. We can use this hook to create ourown specialized element types, eg textbox which only takes numericinput.</wbr></wbr>

Now engine know the definition of all element type, so it next itwill look for form validation function. The form validationfunction to use can be specified in any of theforms<wbr><em>#validate</em>,or<em>formID_validate()<wbr></wbr></em>or<wbr><em>#base_validate()</em>.<wbr><em>#base</em><wbr>isthe value that you specify with the form array.</wbr></wbr></wbr></wbr>

Engine will look for submit function to which the form will besubmitted. They can be specified asvalue<wbr><em>#submit<wbr></wbr></em>for key,or<em>formID_submit()</em><wbr>functionor<wbr><em>#base_submit()</em><wbr>function.Once it gets the submit function for the form itcalls<wbr><em>hook_form_alter()</em><wbr>togive any module which wants to change the form. Basically it’s ourtime to modify someone else’s form to add or remove the inputfields and/or descriptions.</wbr></wbr></wbr></wbr></wbr></wbr>

Form elements are now declared in array fashion, with thehierarchical structure of the form elements themselves as arrayelements (which can be nested), and each form elementsproperties/attributes listed as array elements in key/valuepairs--the key being the name of the property/attribute, and thevalue being the value of the property/attribute. For example,here's how to go about constructing a textfield formelement:

drupal_get_form<wbr>doesthe following:</wbr>

<wbr></wbr>

  • Starts the entire form-building process by gettingthe<wbr><code style="border:0px; background-color:rgb(246,246,242); font-size:0.923em; margin:0px; padding:1px; vertical-align:baseline; font-family:'Bitstream Vera sans Mono',Monaco,'Lucida Console',monospace; line-height:1.5em; white-space:pre-wrap">$form</code><wbr>fromthe builder function</wbr></wbr>
  • Translates the<wbr><code style="border:0px; background-color:rgb(246,246,242); font-size:0.923em; margin:0px; padding:1px; vertical-align:baseline; font-family:'Bitstream Vera sans Mono',Monaco,'Lucida Console',monospace; line-height:1.5em; white-space:pre-wrap">$form['name']</code><wbr>itemsinto actual form elements</wbr></wbr>
  • Performs any validation and "clean-up" that needs to be done, andcalls custom validation functions if declared
  • Submits the form if a submit function is declared, and the form hasbeen submitted
  • Calls any custom theming functions that have been declared
  • Returns an HTML string which contains the actual form.
The preferred method of submitting forms with the API is throughthe use of a form submit function. This has the same namingconvention and arguments as the validation function,except<wbr></wbr> _submit <wbr>isappended instead. Any forms which are submitted from a buttonof<wbr></wbr></wbr> type=> 'submit' <wbr>willbe passed to their corresponding submit function if it isavailable. This method is more secure thangrabbing<wbr></wbr></wbr> $_POST['edit'] <wbr>andusing a switch statement.</wbr>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值