65. 表单Form API

龶龴龳龱龮龪龦龢龡龞龚龴龳龱龘龔龦龑龎龋龉龅龁龀齿齽齻龮龪齹齷齴齷龶 drupal8 齠齝齚齗齓齐龉龅龎齍

龉龅齌齊齈齇齅

齴齃齀鼿鼻龉龅齈齇齝龚鼹齿齴鼵龉龅齹齐鼲鼯鼫齹鼪鼧鼤鼣齹龘鼢齌齊齹齚鼟鼞鼛鼚鼙鼕鼹齿鼔鼑鼍鼛鼊鼤齿齹鼈鼄鼁鼞鼛鼊黿黼黸黵鼧鼑鼍齴鼵黳黲黯黫齴鼵鼙龁黨黳黲齹黧齝黣齗龘鼢龎黢龱齈齇齹 drupal 黠黝齽黜齹龶 drupal 齠黚黖黧黼黓黒齅鼹齿龉龅黑齌齊鼤鼣龶龘鼢齈齇黐黎黋齝齴黇龎齹黆黝黂鼧黫麿麻麹麸黑齌齊鼤鼣麶麵龎麴麳麱麮齹麬麪麦麤齝齌麣麠齴鼵齈齇麟麝齹麟麝齠麙麕龎齝龉龅麶麒龎齌齊齹麎鼵龉龅麒麊麈麆麄黖鼻龮麃鹿鹾鹻鹹齅

龉龅麶麒齅 $form 龉齿齹齐麣龉龅龎鹮鹪麶麒齹鹦齝鹥鹡齹麎鼵齈齇鹠齝龶鹞鹝鹦齍

龉龅麕鹜齅 $formObject 龉齿齹鹍齐鼲龁龀齹鹉鹇龘鼢龉龅齝鹃黼黇鹁鹀黼麹麸鹁鹀黼齌齊鼤鼣齹鸾鸽鸻鸸齍

龉龅鸶鸵麕鹜齅 $form_state 龉齿齹鸬鸩龉龅龎齌齊齈齇齹鸥鸡麄鸟麣龉龅龎鸞鸝黖鸜龘鼢鸛齐

龉龅鸙龢鸗齅 form_builder 龉齿麎鼵齈齇龎鹥鹡鸒鸑黫齹黠齝龉龅齌齊龎鸍鸋齍

drupal 齠鼹齿龉龅黑齌齊龉龅鼤鼣龎鸈鸅齝齴黇龎齹鼤鼣龉龅龎鸃鸂鷿黚黖齝 get 黠黚黖齝 post 齹黿黼龘鼢齝齚齗鷻麝鸽龦齝龶鼹齿龉龅鷷齝龶齌齊鼤鼣鷳鷲鷱鷮麣黖鼻鷫鷧齅

齚鼟齐鼲鼞鷦鸍麶麵鷣黝麟齝 get 鷷齝 post 鷟齹鷜麶麵齠鼞 form_id 鷘鷗齹鷘鷗鷓黑鸽龦龉龅 id 鷐麠齹鷏黓黒鷋龶齌齊鼤鼣齹黖 $form_state->isProcessingInput(); 麦鶵鶴齹齚鼟齌麣鼤鼣齌齊齈齇齠黿黼鶱鸒鸑麹麸黑鼤鼣齌齊鸗齹鶮鼚黆齝鼹齿龉龅齍

鶭麻齐鼲黚黖龶鶪鶨鸗齠鼤鼣龉龅黜齹龘鼢黠齝黚黖龶齇鶦齠鶥鶣鼤鼣龎齹黧鶟黒黖鶞齇鸃鶜鼤鼣齹齚鼟齝黖鶞齇鸃鶜鼤鼣龉龅齹黿黼鶙鶘黝鶕鼞鼹齿龉龅麴麳齹麬齝鶑黓黒鷋龶齌齊鼤鼣齹黖 $form_state->isProgrammed() 麦鷫鷧齍

龉龅鶐鹍齅

鶏鶍齴鼵龉龅齹齐鼲黚黖黝齐龁龀鶌鶉鸗齹黆鶆麃麙麕龉龅龁龀鶃齐鶐鹍鷏黚齹鶁龋龉龅龁龀齿齽齻龮龪齹黿黼龘鼢齝齚齗鶐鹍龎鷳鷲齝鵽鼵鶌鶉鸗龶鸒鸑鷲龶鶐鹍齠鵼龁 _form 鵹黓鵸鼧鶕鵴黂龉龅鶐鹍鵰鵯鸗龎齌齊鷣鶁龱龘龔鶐鹍龮龪鷟齹鶱鵮鸾鵬鵫鶌鶉鸗鵧 '_controller' 鵣黒 controller.form:getContentResult 齹黠鵒齝鵏鵎鵧 controller.form 鵣龎 getContentResult 鸃鸂齹鵌鵏鵎龎鵊黒齅

Drupal\Core\Controller\HtmlFormController

鵂鵁齅龶鶐鹍齠鵬鵫麻 _form 鴿鵸鼧黝鴾鴺鵬鵫 _controller 鴿鵸齹鶮鼚龘鼢黝鶕齓齐龉龅鶐鹍鵰鵯鸗齹黠鵒鼁鼞鼧龑龎鴶鴵麻齹麱齝鴲麱鸒鸑鶐鹍齠 _controller 鵬鵫龎鶌鶉鸗

龉龅鴰齊鶌鶉鸗齅

鵏鵎 id controller.form

鵊齅 Drupal\Core\Controller\HtmlFormController

鸍鸋鸃鸂齅 getContentResult

鶣鴮黖鼻鵏鵎鴭黒鴪麶齅

controller_resolver form_builder class_resolver

黧齝齴鼵鴤鴣龅龎鶌鶉鸗齹龮麃鴠鴾齝龶龉龅鸙龢鸗齠黸黵龎齹鵌鶌鶉鸗黆齝鴜鴚鴪麶麱麮齹麠黇齹龶鴘鴔龎鶌鶉鸗齠鶆麃齐鴒龉龅鶘黠齝鸸齐龉龅鸙龢鸗齹龉龅鸙龢鸗齝龉龅龘鼢龎鹥鹡齹鶁鼻齍

龉龅鸶鸵麕鹜 FormState

鵊齅 \Drupal\Core\Form\FormState

鶣鸋齅 \Drupal\Core\Form\FormStateInterface

龉龅齌齊鶘鴏齇鸥鸡鷐鸟鸞鸝齹鴌鴈鴄齇鶦黠黚黖齐鹦鴃鴀鼔鳿鳻鸞鸝齹齐鼲鼤鼣龎麶麵黠鳷鴀龶黧鳶齍

龉龅麕鹜齅

麃黸黵齴鼵龉龅齹龘鼢黆鶆麃齐鼲鼤鸜鳳鼵鳱麃龎鸞鸝齅鵼龁齴鼵鶴鳰 id 齹龉龅鳭鳫齝鹃黼鷲鹀黼麹麸鷲鼤鼣鹀黼齌齊鷲黎鳧鳤齀鵒鹍龘鼢鳡鳟麻齹鳝鳜黝鳙龎鳘鹡齹鳕鶙龉龅麕鹜黋鳔龎鶣鸋齅

\Drupal\Core\Form\FormInterface

黆鼞鳳鼵鸃鸂齹齐鼲黆鶆麃鼤鸜齴鼵龉龅麕鹜鵒鴾黋鳔龉龅鴠鴾齹鶙鳳鼵鸃鸂黒齅

\Drupal\Core\Form\FormInterface::getFormId

鳒鸻龉龅 id 齹龘鼢齐鵌 id 鶴鳰龉龅齹龁龀龮龪鳏鳍齹鴔黂鹦鳊鳇龉龅麶麒鳄鳃鳏鳍齹黧黠齝龘鼢鷫鳰龉龅齝鶮齌麣鼤鼣鸶鸵龎鸟鲿齍

\Drupal\Core\Form\FormInterface::buildForm

龁龀龉龅齝鹃黼齹鳒鸻黢龱龎龉龅鹮鹪麶麒齹龶鶣鸋齠鲻鼪黆龁龀麻鲺鼵鴪麶齹黚齝鲸鲶龶黋鳔齠黚黖龁龀鲵麿鴪麶齹龶鸛齐齠鲳黜龁龀龎鴪麶鴄黖鼻鲺鲱齀鼿鳿鸍齅

龶鸛齐龉龅鶐鹍鶘齹黧鲯鴪麶龎鷓龶鳭鴈鸛齐鶌鶉鸗鲮鲪鸗鷣鵏鵎 id controller_resolver 鷟鲩鲦鲥鲤麕鹜齠鲢鷱齹黧黑鴘鴔鶌鶉鸗龎鴪麶鲮鲪齴黇齹龶 $request->attributes $request->attributes->get('_raw_variables') 齠龎鴪麶鹠鴾鲢鷱齹鷷鴾鲙鴒鲥鲤麕鹜鹁鶐鹍鲗鲔鸗麕鹜齹鳕鶙龶鶐鹍龁龀齠鲒鲑龎鴪麶黠齝鴾鲢鷱龎齹鳕黒鲏鲶鶑鵬鵫龶麻鲥鲤麕鹜齠齹黧鳶鶆麃鲍鳰鵂鵁齅鳕黒鴪麶鲮鲪齝齐鼈鲊鲉鶉鲢鲙龎齹鲅黖黧鼵鸃鸂齠龦鲺鼵鴪麶龎鴪麶鲂鳱鱾黒 $form $form_state 鶮鼚龘鼢鶕鼤齿鱽黝鴒鴪麶麱鱺鼍鱹鱶齍

龶鸛齐龉龅鸙龢鸗龎鲙鴒龉龅鶘齅

\Drupal::formBuilder()->getForm('Drupal\mymodule\Form\ExampleForm')

黚黖龶鱰齴鼵鴪麶鼧鱯鱫黎鳧鴪麶齹鳧鲶鶕鶑鱧鱥鳿鸍龉龅麕鹜龎 buildForm 鸃鸂齍

鲸鲶黚黖龶鵌鸃鸂齠鶥鶣鳒鸻齴鼵黳黲麕鹜齹黧龶鸽龦鱤龱 drupal8.4 齝鱟鱞龎齹鵌黳黲齝黖鱹鱶龎鸃鶜鳒鸻鼑 http 鹥鹡齹鴔黂鱹鱶鶌鶉齈鳇鼑齐鼲鱛鲻鼪鱹鱶黝黲鵌齐麣鴰鱘齈鶌鶉齹鱔鴰鱘鵂鱑黠麤麻黧齝鹍麣鸽龦龉龅 api http 鹥鹡黋鳔黐鼞鱎鱍齹黝鲙麮麱黒鼄齍

龉龅鸙龢鸗齅

鵏鵎 id form_builder

鵊齅 Drupal\Core\Form\FormBuilder

龉龅齈齇龎鹥鹡鶌鶉黫齹黋齽鱉龉龅麕鹜齹鲦龉龅麕鹜龎鸙龢龉龅鸃鸂齠鷱鸻龉龅麶麒齹鱇鴚龉龅麶麒齹黒黎鱯鱫鳱麃龎鱃鰿黑鳍鹿鹾齹鳊鳇鳄鳃鳏鳍齹齌齊龉龅鰻鰻鹠龶黧鳶黸黵齹黖鼻齝鳧龎龮麃鸃鸂麤鰸齅

\Drupal\Core\Form\FormBuilder::getFormId

黋齽鱉龉龅麕鹜齹鼔鶱黎鵂鸍鴒 $form_state 齹鳒鸻龉龅 id

\Drupal\Core\Form\FormBuilder::retrieveForm

鸙龢鰷鰳龎龉龅麶麒齹黒黎鱯鱫鳱麃龎鵊鱃鰿齹鸸齐龉龅麕鹜龎鸙鰲龉龅 buildForm 鸃鸂齹鰮鰫鰨鰤龉龅麶麒

\Drupal\Core\Form\FormBuilder::prepareForm

黒龉龅麶麒 $form 鱯鱫鳱麃龎鹿鹾齹鱃鰿齚齅 #action #method #build_id #token #id #validate #submit #theme 齹鳍鹿鹾齚齅 form_build_id form_token form_id 齹鸒鸑龉龅麶麒龎鳄鳃鳏鳍齹鵹黓龎鳏鳍鲂鼞齅 'form' 'form_' . $base_form_id 'form_' . $form_id 齹鳏鳍龎鰞麶鲂鼞齅

hook_form_alter() hook_form_BASE_FORM_ID_alter() hook_form_FORM_ID_alter()

鰖鵬鰒鰐鲂黒 yunke 齹龉龅 id yunkeId 齹龉龅黢龱 id 黒齅 yunkeBaseId 黿黼鳏鳍龎鰞麶鲂黒齅

yunke_form_alter()

yunke_form_yunkeBaseId_alter()

yunke_form_yunkeId_alter()

黧鲯鳄鳃鳏鳍鰞麶鶣鴮鴪麶齅 $form, $form_state, $form_id 黎齠 $form 黲鵌黖鰊齐鸃鶜鶣鴮

鰉齚齅 \core\modules\contact\contact.module 齠龎黖鼻鰞麶齅

contact_form_user_form_alter(&$form, FormStateInterface $form_state)

鵂鵁齅龉龅鰃鴀齠鵒鳷鴀龎齝鵴黂鵌鸃鸂鳒鸻龎龉龅齹齚鼟龉龅鸶鸵鶑鵬鵫黒黝黚鰃鴀齹黿黼鶱黝鶕鸛齐鰃鴀龘鼢

\Drupal\Core\Form\FormBuilder::processForm

鸸齐麹麸鸗黑鼤鼣鸗鸒鸑麹麸黑鼤鼣

\Drupal\Core\Form\FormBuilder::doBuildForm

龶鵌鸃鸂齠麮鵴鶱龉龅麶麒鸽鹮鹪麶麒齷鰁麻齹鶕鱧鲸鸸齐黖鳻鯽齌齊鲅鼞龎鳍鹿鹾齹龉龅麶麒黝齝黆鴾鳡鯼龉龅鹿鹾齹鹦黠黚黖鳡鯼黎鳧龎 html 鹿鹾龎鱛鵂鵁龉龅鰃鴀龘鼢鰃鴀龎齝鼁鼞鵴黂鵌鸃鸂齌齊龎龉龅麶麒鷣麕鳍鹿鹾鯻鵴鳻鯽齹黠鯻鸒鸑 #processed #after_build 鰻鸻鸸鷟齹鱔齝鶮鰃鴀鯺鴒鵌鸃鸂鯷黳鱛鵌鸃鸂齌齊齚鼻齅

鯴麵鹿鹾龎 #type 鱃鰿齹鸸齐鹿鹾鸞鸝鯲麊麟齊鸗鵮鸾鵹黓龎鱃鰿鳭鳫鱛

黒鲅鼞鹿鹾鱯鱫黢龱龎鴔齐龎鱃鰿鱛

鷫鳰龉龅齝鶮鯰齐 https 鼤鼣鱛

鶱龉龅麶麒黖鰊齐鸃鶜鳷鴀鴒 $form_state 齹黧鱟鱞黎鲏齇鶦鲙鴒麎鼵龉龅麶麒

齚鼟鷦鸍齠鴀龶鷘鷗 form_id 齹鷜鰻麣鸽龦龉龅 id 齹黿黼黒 $form_state 鵬鵫鯮鶵鷣 $form_state->setProcessInput(); 鷟齹黧龉鰸龘鼢黝齝龶鼹齿龉龅齹麱齝龶齌齊鼤鼣齹鼧鯪鶱鸒鸑麹麸黑鼤鼣齌齊鱛

齚鼟齝龶齌齊鼤鼣齹黿黼龶麃鲤 csrfToken 鶘鶱麹麸 Token

鵬鵫 data-drupal-selector id 龎鱃鰿鷓

齚鼟鴀龶 #description 齹黿黼鵬鵫 aria-describedby 鱃鰿

齚鼟 #input 黝黒鯣齹黿黼鴲鱉鹿鹾龎鷦鸍鹁鵬鵫 #value 鱃鰿鹁鴮鯠鯜鯚鹿鹾鹁鯗龁鯓鳇鹿鹾齹鵂鵁齅龶鹿鹾鸞鸝鯲麊麟齊鸗齠鯐齴鼵黚鷦鸍龉龅鹿鹾鹠鵹黓鵬鵫麻 #input 鱃鰿齹黎鷓黒 true

齚鼟鴀龶 #process 鷜鷷鼁鼞鸒鸑黂齹黿黼鸒鸑齹齐麣麕鹿鹾鯍鸑鲍鳰鳄鳃齹鳿鳻鯋鼵鴪麶齅 &$element, &$form_state, &$complete_form

鷫鷧黚鶏鶍鰿齹鳻鯽齌齊鳍鹿鹾齹鳿鳻 #tree #access #disabled #allow_focus #parents #array_parents #weight 鼑鳍鹿鹾鼔鯉鷓齹齚鼟鯈鹿鹾鯅鯁鶏鶍齹黿黼鳍鹿鹾黠鵒鯅鯁鶏鶍麻齹黧鵒齝 $inherited_access 龎鹝齐

鸒鸑 #after_build 鸻鸸

鷫鷧齝鶮鼞 #type file 龎鹿鹾齹黖鷮龁龉龅鶞鱘

鵬鵫龉龅龎鶞鱘 enctype

齌齊鯓鳇鼤鼣龎鹿鹾齹鼔鵬鵫麹麸黑鼤鼣齌齊鸗齹鯓鳇鹿鹾黐龎齌齊鸗鯀龚麣龉龅黐龎齹齴鮿鵬鵫齹鼧黫黝鶕鶑鸒鸑

\Drupal\Core\Form\FormBuilder::handleInputElement

鳷鮽鸃鸂齹齚鼟鹿鹾 '#input' 鱃鰿黝黒鯣鷣龶龘鼢齠鲅鼞鮻鴚鷦鸍鴾鮹龎龉龅鹿鹾鹠鶕鵹黓鵬鵫鵌鱃鰿齹鷓黒 true 齹鶁鹿鹾鸞鸝鯲麊麟齊鸗鷟齹黿黼鴲鱉鹿鹾龎鷦鸍鹁鵬鵫 #value 鱃鰿鹁鴮鯠鯜鯚鹿鹾鹁鯗龁鯓鳇鹿鹾鰻

龉龅鷓鸻鸸齅

龉龅鼤鼣鼧鶆麃鶱鼤鼣龎鷓鴲鱉黒麃麹麸龎鷓齹鵂鵁齝鷓鴲鱉齹麱黝齝鷓麹麸齹麹麸鹝齐龶鴲鱉鼧龎鷓黐齹黠鵒齝鶱 $form_state->getUserInput() 鴲鱉黒 $form_state->getValues() 齹鴲鱉鰞麶鮰黎鯀龚鮮齝鷣鯀龚鮮鲦鮫鴒鮧鷟齅

#value_callback 鱃鰿鵼龁龎鸻鸸

'form_type_' . $element['#type'] . '_value' 鮞鲂龎鰞麶

\Drupal\Core\Render\Element\FormElement::valueCallback 鵹黓鸻鸸

鮜鮛鯓鳇鹿鹾齅

龘鼢鶆麃鷻麝齝鵽齴鼵鹿鹾鯓鳇麻龉龅鼤鼣齹黧鳶鼞 AJAX 鼤鼣黑鶪鶨鸗鮒鮏鼤鼣鲺鲱齅

鸽鴔黂 AJAX 鼤鼣龉龅鶘黖 _triggering_element_name 鴪麶鵼鰸鯓鳇鹿鹾龎鲂鮌齹黚鴿龎黖 _triggering_element_value 鴪麶鵼鰸鯓鳇鹿鹾龎鹿鹾鷓

Ajax 鸃鶜黜齹龉龅黆黚鴾鶑鮒鮏鯜鯚鼤鼣齹齚鼟鯜鯚鲂黑鯜鯚鷓鼍鳔龶鷦鸍齠齹黿黼鹦鵒齝鯓鳇鹿鹾齹黧鳶鮊鮉鯜鯚齝齴鲱鲍鮅齀鼿齹鶪鶨鸗鳿鳻龎齝鮒鮏鮊鮉鯜鯚龎鮃鶵鷓齹龘鼢鴔黂黒鮊鮉鯜鯚鲔鵫 #has_garbage_value 鱃鰿黖鶴鳰黧鲱鼤鼣齹鶙鶘鼤鼣龎鷓齴龁黝鶕齝鯣鷓齍

鼞齴鲱鲍鮅齀鼿齹鸽龉龅鳡鯼齴鼵 textfield 鷦鸍鮂齹鶙鶘鯜鼻鸻鮀鲿鼧齹 Internet Explorer 鶪鶨鸗鼤鼣龎麶麵齠黝鳡鯼黣齗鯓鳇鼤鼣龎鹿鹾齹黎鳧鶪鶨鸗黖鱰齴鼵鯜鯚鹝黒鯓鳇鹿鹾齹鲅黖鶙鲱齀鼿鳇鰫鶘鼢齴黖鱰齴鼵鯜鯚鹝黒鯓鳇鹿鹾齍

龉龅麶麒齅

龉龅麶麒齝齐麣龉龅龎鹮鹪麶麒齹齝鹮鹪麶麒龎齴鼵鳍鯠齹鼞鲯鱃鰿黆齐麣鲍龁龎龉龅鹿鹾齹鲏鲶龶鹿鹾鵊龎鵂鱑魾魽齠鶑鲮鱑齹鼞鲯黚齐麣鴏鴈龉龅鹿鹾鱛 黚齐麣鴏鴈龉龅鹿鹾龎鱃鰿 齚鼻齅

#ajax 鵼龁麻 Ajax 鸑黒龎鹿鹾麶麒齹鲵麿鸞鸝鶁 ajax 龮龪

#array_parents 黆龳龎鮌魹魵麶麒齹鹿鹾鷓齝龶龉龅鹮鹪麶麒齠鲦鯴鹿鹾鹹鰤鴒鱧魲龎鹿鹾鲂齹鳡魯鱧魲齹龶魫魨鶘鵌麶麒黒鯣齹鴏鴈龉龅鹿鹾鹠鼞鶙鱃鰿齍黠鴪齷 #parents, #tree

#parents 黆龳龎鮌魹魵麶麒齹麃齊鲮鵌鱃鰿鶆麃龚鰸魧龉龅鼤鼣鴒龘鼢齠龎麶麵黚黖齝齴鼵麿魤麶麒齹龶鴤麿齀鼿鼻鲸鲶黆鸛齐麻齴魤麶麒鷣 $_POST 齝齴魤龎鷟齹鱔鹦黚黖齝麿魤龎齹鷜黧黇鲑麦鵯魠龎鴠鴾齹黧黇鴾龉魝龉龅齠鷓魚鷓鼄魖龎鸟龘齹龶龦魓鴔黂龉龅龎 name 鱃鰿黋鳔齹 name 鱃鰿黚黖鵼龁麿魤麶麒齹齚齅 name="price[car][jac][heyue]" 黧黇龎 name 鷓黚黖龉齿魌鮀魋鵊鼻魈魅魋魁黑鬾龘龔鬼鮀龎鬸鬴齹鰸魧黧鼵鷻鶴鮒鼧鵒黝鬳齊鲮 #parents 鱃鰿麻齹鵌鱃鰿鷓鯺鴒 #tree 鱃鰿龎鯷黳齹 #tree 龉齿鷓齝鶮鴀龶鬰鲱黐鼻鮮鸟龘齹齝齴鼵鬬鬩鷓齹齚龦魾鼤鴒龎鵧魌鮀鹁魋魁鹁龘龔鵣齹齚鼟 #tree false 黿黼黆鼞齴鼵鹿鹾鷣龱鹿鹾龎鹿鹾鲂鷟齹齚鼟黒 true 黿黼鳡鯼鯈鹿鹾龎鲂鮌齹黚黖黧黼齊鲮齅齚鼟鼤鼣鷓鬨鳔鬤鬣鸙鷣鼞黐鼻鮮鸟龘鷟齹黿黼鵌鱃鰿鴰龉鷓龶鬤齠龎鶐鬟齹齐麣鲦 $form_state 齠鲢鷱鷓齹鰉齚鷓黒 $value[‘a’][‘b’][‘c’] 黿黼鵌鱃鰿鷓鵒齝 [‘a’,’b’,’c’] 齹龶齇鶦齠鼞鶘鬙鬗鬓鴭 section 齹龶龉龅麶麒龎魫魨鶘鵌麶麒黒鯣齹鬐鬏鬎麤鹦鵼齿齚齗龶麿魤麶麒 $_POST 齠鱽鴒鷓齹黠鴪齷齅 #array_parents, #tree 齹鵌鱃鰿魚 #array_parents 龎鬊鳰齝鲏鴰龉鼤鼣鷓龎鬣鸙鶐鬟齹麱鼧黫鴰龉龉龅麶麒鹿鹾龎鶐鬟齹龉龅麶麒鹿鹾黚黖齝黣鵁鹿鹾齹黚鴾鼁鼞鷓齍

#tree 鬬鬩鷓齹鵹黓黒 false 齹龶鳭鴈鲅鼞龎龉龅鹿鹾鹠鶕鶑鬇鱫鵬鵫齹鼞鲯龉龅鹿鹾龎鷦鸍鷓齝鼞鬤鸶鸟龘龎齹鵌鱃鰿龉鰸齝鶮鮻鴚鬤鸟龘齹鵼齿龶 $form_state 齠鹿鹾黑鳍鹿鹾龎鷓齝鶮黒鴄魨鬅龎齹黠鶁齅 #parents, #array_parents

#default_value 鵹黓鷓齹黠鴪鬂 #value.

#description 龶齐鼲鬁龑齠龎髾髻黯髹髸魾龱齹鴔鱶 #title 麮鵴髶黖髹髸鹿鹾齹鲅黖魠麿麶鹿鹾黝黲鼞黧鼵鱃鰿齹齚鼟鯗黋鶆麃齹黿黼鯗鳷齝髲髯鼧龎魾龱齹齚鼟黝齝 markup 麕鹜 齹黿黼鶕鯍鸑 XSS 髭鴏黂髩

#description_display 髹髸鼹齿髧鵫鮰鸃鶜齹齚齅 after 齹鶁 #title_display

#element_validate 齴鼵鸻鸸麶麒齹鶑鸸齐麦麹麸齐鼲鷦鸍齹鴪麶鼞齅 $element, $form_state, $form

#field_prefix 鮌髤龦髡齹鼹齿龶鷦鸍鹿鹾龎龦龑齹黲鵌齝髲髯鼧龎鷓齹齚鼟黝齝 markup 麕鹜黿黼鶕鯍鸑 xss 黂髩

#field_suffix 魚龦髡鷐麠齹鼹齿龶鹿鹾鼧龑

#input 鬬鬩鷓齹龉齿鹿鹾齝鶮鶣鯺鷦鸍齹鲅鼞黚鶣鯺鷦鸍龎鹿鹾鹠鶑鵹黓鬇鱫齹鷜鷓黒 true

#process 鸻鸸麶麒齹麙麕鹿鹾鴭鲍鮅齌齊齹龶龉龅鸙龢髠魖鶑鸸齐齹鴪麶齅 &$element, &$form_state, &$complete_form 齹鱰齴鼵鴪麶黒鵬鵫鵌鱃鰿龎龉龅麶麒齠龎鹿鹾齹鰷鼧齴鼵鴪麶齝黸麎龎龉龅麶麒齍鸻鸸鶆麃鳒鸻齌齊鼧龎 $element

#processed 鬬鬩鷓齹 true 龉鰸龉龅麮鵴鶑 #process 鸻鸸齌齊黂齹齚鼟鵬鵫黚黖髜鯁鸻鸸鸒鸑齍

#after_build 齴鼵鹍鸻鸸鸙黵龎麶麒齹鹦鲶龶鹿鹾鶑鸙龢鼧鸸齐鷣鳡魯鳍鹿鹾鷟齹鸸齐鶘鷦鸍鷓麮鵴鶑鴲鬐齹 #process 鸻鸸麮鵴鶑鸒鸑齹鴪麶齝齅 $element, &$form_state 齍鵂鵁魚 #process 黝麠齹鱰齴鼵鴪麶黝齝黖鰊齐鳿鳻齹鸻鸸鶆麃鳒鸻齌齊鼧龎 $element

#after_build_done 鬬鬩鷓齹鵼齿 #after_build 鸻鸸齝鶮麮鵴鸒鸑齹齚鼟鵬鵫黚黖髜鯁鸻鸸鸒鸑

#required 鬬鬩鷓齹龉鰸鹿鹾齝鶮黒鳱鱾鷦鸍龎齍

#states 齐麣 JavaScript 龎鸶鸵鸞鸝麶麒齹鰉齚鯴麵髛黜齴鼵鹿鹾龎鷦鸍齀鼿麱龁龎黧鼵鹿鹾齝高體鷷齝鼹齿齹鲵麿鶁齅 drupal_process_states()

#title 龉龅鹿鹾龎鶵龪齹齝齴鼵髲髯鼧龎鮌魹魵齍

#title_display 鵼龁 #title 龎髧鵫黑鼹齿鸃鶜齹黚鴾龎鷓鼞齅 before 鷣鹿鹾龎龦龑齹魠麿麶鹿鹾龎鵹黓鷓鷟鹁 after 鷣鹿鹾龎鼧龑齹 radio 鹿鹾龎鵹黓鷓鷟鹁 invisible 鷣齐 css 高體鷟鹁 attribute 鷣鯰齐髓鼍鼤齿 tooltip 鷟齍

#value_callback 鷓鸻鸸齹齐麣鴲鬐齐鼲鷦鸍鴒鹿鹾龎鷓齹鴪麶黒齅 $element, $input, $form_state 齍齚鼟鼁鼞鵹黓齐齅

'form_type_' . $element['#type'] . '_value' 齹鴺鼁鼞鵒齐齅

\Drupal\Core\Render\Element\FormElement::valueCallback

#errors 鼛鼊鸞鸝

#attributes 鱃鰿麶麒齹鵼龁鹿鹾龎鱃鰿齹齚 :

$form['#attributes']['class'][]=鵣yunke鵣;

$form['#attributes']['autocomplete'][]=鵣off鵣;

$form['#attributes']['data-drupal-selector']=鵣yunke鵣;

黆鴾齐麣鲍龁龉龅鹿鹾龎鱃鰿齚鼻齅

#https 鬬鬩鷓齹黆齐麣龉龅鹿鹾鷣 '#type' == 'form' 齹齚鼟黒 true 齹黿黼鶱鸛齐 https action

#disabled 鬬鬩鷓齹齚鼟黒 true 齹黿黼鴾髐鼹齿齹鱔齌麣鯅齐鸶鸵齹齐鼲黝鴾鷦鸍鷓

#method 鼤鼣龉龅龎鸃鸂齹髍齐麣龉龅鹿鹾鷣 '#type' == 'form' 鷟齹鵹黓黒 post 齹鯻鵬龁鶘黠黚黖龶龉龅鸶鸵麕鹜齠鵼龁黒 get $form_state->setMethod("get"); 鷟齹齴鮿鵬龁鵒黖鵬龁黒鴜齍

#build_id 髍齐麣龉龅鹿鹾鷣 '#type' == 'form' 鷟齹鵼龁鰃鴀 id 齹鵹黓黒 form- 龦髡龎鸩鲉鮌魹魵

#token 髍齐麣龉龅鹿鹾鷣 '#type' == 'form' 鷟齹鵼龁 CSRF token 齹黝鸛齐鼚鵬鵫黒 false 齹鼈鼄鵬龁黒 true

#input 髍齐麣鴾鶣鯺齐鼲鷦鸍龎龉龅鹿鹾齹鶟黒鷦鸍鹿鹾齹龶鹿鹾鸞鸝鯲麊麟齊鸗齠鵹黓鵬鵫麻 '#input' => TRUE 齹鸽龘鼢鳇鳔鴀龶鵌鱃鰿鶘齹鶕鯍鸑鷦鸍鷓龎鴲鬐

#value 髍髋麣鷦鸍龉龅鹿鹾齹鷓齝鵴黂鸻鸸鰞麶齌齊黂龎齹黠鵒齝 $form_state->getValues() 麱黝齝 $form_state->getUserInput() 齹鶙黂齇龶龉龅鸙龢鸗龎 handleInputElement 鸃鸂齠鯍鸑

#required_but_empty 龉齿鹿鹾齝鳱鼯鵸齹鱔齐鼲鼁鼞鷦鸍

#limit_validation_errors 齐麣鯓鳇鼤鼣龎鹿鹾齹鯍鸑鼛鼊髊鶉齹鼞鲯鯜鯚黐龑鵬鵫麻鶃髆龎鼤鼣齌齊鸗齹鸽鮒鮏鼤鼣鼧黝鶕鸒鸑龉龅鮮鳰龎鼤鼣齌齊鸗齹麱齝鹦黐龑鵬鵫龎鶃髆龎鼤鼣齌齊鸗齹齚鵧黐齴麴鵣鹁鵧鱯鱫鲵麿鵣齹鶙鶘鷏髅鱶髂鷦鸍鳝骿黠鶆麃鸒鸑鹦龎鼤鼣齌齊鸗齹黖鯍鸑鼙龁黨鼄鵊龎鹞鹝齹鶙鶘鵒鶆麃鼛鼊髊鶉齹髍鸟鵂鵌鯜鯚鶆麃鸟鵂龎鼛鼊齹黎鳧鼛鼊齴骽黝麟鱛鵌鱃鰿黆鼞龶鼤鼣鹿鹾鵬鵫麻 #submit 鶘骹鼞骿齹齝齴鼵麶麒鷓齹龘鼢黆鸟鹡鵌麶麒齠鵬鵫龎鹿鹾龎鼛鼊齹黎鳧鼛鼊鹠鶑髊鶉齹鵌麶麒龎鹿鹾鷓齝龉龅鹿鹾龎 #parents 鱃鰿麶麒鱛龶龘鼢齠鵌鱃鰿鶑齌齊鼧鯉鷓鼑齅 $form_state->limit_validation_errors 鱃鰿齹鼧黫黆鴾齝 NULL 黯麶麒齹鴏鰻麣 NULL 鶱鸥鸡鲅鼞鼛鼊齹黧齝鹦龎鵹黓鷓齹齚鼟黒麶麒齹黿黼黆鼞龶黎齠龎鹿鹾骹鸥鸡鼛鼊齹鯣麶麒鵧 [] 鵣鶱黝鸥鸡黣齗鼛鼊齹齚鼟黝黒鯣麶麒黿黼鵌麶麒龎鹿鹾齝龉龅鹿鹾龎 #parents 鱃鰿麶麒 齹龉齿鹦鴰龉龎鹿鹾鶱鶕鸥鸡鼛鼊齹麱黎鳧龎黝鶕鶑鸥鸡鼛鼊

#submit 齐麣龉龅麶麒鯴鹿鹾黯黫鯓鳇龉龅鼤鼣龎鹿鹾齹齝齴鼵鹍齴鼵黯麿鼵鼤鼣齌齊鸗鸻鸸鸙黵龎麶麒

#validate 齐麣龉龅麶麒鯴鹿鹾黯黫鯓鳇龉龅鼤鼣龎鹿鹾齹齝齴鼵鹍齴鼵黯麿鼵麹麸齌齊鸗鸻鸸鸙黵龎麶麒

#executes_submit_callback 齐麣鯓鳇龉龅鼤鼣龎鹿鹾齹鬬鬩鷓齹黆鼞鯓鳇鹿鹾龎鵌鱃鰿黒骰齹骹鶕鸒鸑鼤鼣齌齊鸗齹黧鵁骮麄黆鼞鶑鱟鱞龎鼤鼣鯜鯚骹鴾鼤鼣龉龅齹鶮鼚鷏鸛鼤鼣麻黠黝鶕鶑齌齊齍

鲵麿鶃齐鱃鰿鶁鹿鹾鵊骬鷣龱龘龔龎鹿鹾鵊骬鯲麊麟齊鸗鷟

黖鶞齇鸃鶜鼤鼣龉龅齅

龉龅鴔鱶齝鹍齐鼲鲦鶪鶨鸗齠鼤鼣龎齹鱔鲸鲶黠黚黖鲦齇鶦齠鼤鼣齹鸸齐黖鼻鴰鱘鷏黚齅

\Drupal::formBuilder()->submitForm($form_arg, FormStateInterface &$form_state);

$form_arg 黒鴏髋龁龉龅鵊鲂黯龉龅麕鹜

龶鸸齐龦鲸鲶黚黖鴔黂黖鼻鴰鱘鵬鵫鶆麃鼤鼣龎鷓齅

$form_state->setValues(array $values);

鵂鵁黝齝 $form_state->setUserInput(array $values); 黧鶱鳝骿

鶆麃鳿鳻鼑龉龅麕鹜 buildForm 鸃鸂龎鲳黜鴪麶黚黖鴔黂黖鼻鴰鱘鵬鵫齅

$form_state->addBuildInfo('args', $args);

黯黫鶥鶣龶 submitForm 鸃鸂齠鳿鳻

黖鶞齇鸃鶜鼤鼣龉龅鶱骨骤龉龅鳒鸻龎黳黲

龉龅鰃鴀齅

齐麣鼤鸜龉龅麶麒 form 龉龅鸶鸵麕鹜 form state 龎鰃鴀鵏鵎齹黧齝齴鼵齐麣龉龅鸙龢鸗龎骣鼞鵏鵎齅

鵊齅 Drupal\Core\Form\FormCache

鶣鸋齅 \Drupal\Core\Form\FormCacheInterface

鵹黓齀鼿鼻鼔黝鯍鸑鰃鴀齹鳭鴈鸛齐鼞髠髋髋鶉龎鲿鷓鴃鴀鵏鵎鷣鶁龱龘龔鲿鷓鴃鴀龮龪鷟齹黖龉龅鸙龢 id 鹝黒鰃鴀 id 齹鵂鵁黝齝龉龅 id 齹鯐齴鬅鶏鶍龉龅黎龉龅鸙龢 id 鹠鶕鳃鷘齹鳕鶙鰃鴀黆鴾鷱鸻黐齴鬅鰃鴀龎麶麵齹麶麵鶑鴃鴀龶黖鼻麶麵骠龉齠齅

key_value_expire

鵌鴃鴀鸗鼞齴鼵鲍鰿齅鴃鴀鶘魖鼞齴鼵髠髋齹齚鼟骟髠黿黼鴃鴀骛骿齹鵹黓黒 6 骗鶘齹黠鵒齝 21600 骒齹鵌鷓黚黖龶鲔鵫魾麊齠鲔鵫齹鲔鵫鲿黒齅 form_cache_expiration 齹龅髧黒骒

龶鰃鴀鶘黠鵬鵫麻鰃鴀麹麸鱘 #cache_token 齹鵁骮麄鶕鬎齠龎 Csrf Token Seed 鳃鷘黯黫骎验鸶鸵鳃鷘齹鰃鴀黠鶱骛骿齍

龉龅鰃鴀黒鹃黼黝鸛齐龘鼢龎鰃鴀鵏鵎鷳鷲黿齝鳕黒鲏黝骋鮰鰃鴀鶵骈鹁黐鼻魾齹鼞骅龁龎鰃鴀鲿齹龶龉龅鰃鴀齠 form_build_id 鷐鸽麣鰃鴀 id

鵂鵁龶龉龅鰃鴀龘鼢齠鶕鱫骃龉龅鸶鸵麕鹜齠鵼龁龎魾麊齹黠鵒齝 $build_info['files']

龉龅鰃鴀龶黂髠鶘齹鲢鷱鶕鱧鱥骂鶭鰃鴀齹鱔齚鼟鼁鼞鳇鰫鲢鷱鱥鹝鵒鶕齴鶥鴀骀龶鰃鴀齠齹鶆麃齓鸑鱧鱥黣鵎黖驼鶭鲏

龶鲥鲤齝黝黲鵌鰮鰫驺鹝齐龎鲥鲤鶘鷣齚 'GET', 'HEAD' 鷟齹黝鴾鯍鸑鰃鴀

麹麸齌齊鸗齅

龘鼢龶黖鼻鵏鵎齠鯍鸑龉龅麹麸鴶鴵齅

鵏鵎 id form_validator

鵊齅 Drupal\Core\Form\FormValidator

鶣鸋齅 \Drupal\Core\Form\FormValidatorInterface

龶龉龅鼤鼣齌齊龦齹龘鼢鶱鸒鸑麹麸齌齊鸗鯍鸑龉龅麹麸齹鵹黓龉龅黆麹麸齴鬅齹齚鼟麮鵴麹麸黂鶱黝鴺麹麸齹黖 $form_state->isValidationComplete() 鹝黒鷫鳰鶵鶴齹麹麸龎鷓齝 $form_state->getValues() 齹麱黝齝 $form_state->getUserInput() 齹龶麹麸鶘黧鲺鲱鷓龎鴲鬐麮鵴龶鹿鹾龎 #value_callback 鸻鸸齠黸黵麻鱛麹麸龦龚鯍鸑 CSRF token 麹麸齹鼪鼧麎鼵麹麸黂齇鵒齝麕龉龅麶麒龎驵驳黂齇齹鯰齐驯驭鯀龚驵驳驩鸂齹驥鳍驤鮒龚齌齊齹麠鮮鳰驤鮒鯜驠鹿鹾龎 #weight 鱃鰿驜鶦驙鬅鯍鸑齹鼁鼞 #weight 黯黫鷐麠黿黼鯜驠鹿鹾鼍鳔龶龉龅齠龎驘鶦鯍鸑鱛麹麸黸黵鼧鶱黒鹿鹾鵬鵫鱃鰿 #validated true 齹鹦鵁黒麮鵴鸒鸑麻麹麸齹 鲸鲶黚黖驗齐黧鮒鱇鵬鵫鵌鱃鰿鲩髜鯁麹麸齍

麹麸齝龶麹麸齌齊鸗齠鯍鸑龎齹黎黒齴鼵驕鸂龎鸻鸸鰞麶黯鸃鸂齹麙麕麠齴鵸麹麸黚黖鵬鵫麿鼵麹麸齌齊鸗齹麹麸齌齊鸗鴄黒鲺魠鵊鳰齅鳍鹿鹾鮮鳰黑龉龅鮮鳰齍

龶龉龅麶麒龎黣鵁鳍鹿鹾黐鹠黚黖鵬鵫 '#element_validate' 鱃鰿麦麹麸麙麕鵌鳍鹿鹾龎鳍鹿鹾鮮鳰龎麹麸鸗齹鵌鱃鰿龎鷓齝齴鼵鹍齴鼵黯麿鼵麹麸鸗鸻鸸鸙黵龎麶麒齹麹麸鸗鸻鸸龎鴪麶黒 &$elements, &$form_state, &$complete_form 齹鹍麣龉龅麶麒齝龚鲦鳍鹿鹾鴺鴒鯴鹿鹾龎驘鶦驵驳麹麸齹鲅黖鳍鹿鹾麹麸黂齇鶱龶龉龅鮮鳰龎麹麸鼄龦鯍鸑齍

鸽鲅鼞鳍鹿鹾鮮鳰龎麹麸黸黵鼧齹鶱鯍鸑龉龅鮮鳰龎麹麸齹鶙麹麸鬗鴄黒鲺鲱齅鯓鳇鹿鹾鷣鯓鳇龉龅鼤鼣龎鹿鹾鷟黐鵬鵫龎麹麸黑龉龅鯴鹿鹾黐鵬鵫龎麹麸齹龦黫鯀龚鮮鮫麣鼧黫鱛龉龅鮮麹麸齌齊鸗黑鹿鹾鮮鷐鰉鴪麶黝齴黇齹鹦鲶黖鰊齐鸃鶜鶣鴮黸麎龎龉龅麶麒 $form $form_state

鯓鳇鹿鹾黐鵬鵫龎麹麸齝龶鴌鼵鯓鳇龉龅鼤鼣龎鯜鯚黯鹿鹾黐鵬鵫龎麹麸齌齊鸗齹鴔黂鱃鰿 #validate 鵼龁齹黎鷓鬴鶜黑 #element_validate 齴黇齹齝齴鼵鹍齴鼵黯麿鼵鸻鸸麹麸鸗麒黵龎麶麒齹黧鱟鱞鴤魠龎驔驒鰿齹鸽齐鼲鯓鳇麻龉龅鼤鼣齹龘鼢驐龚驌鮛鯓鳇鹿鹾齹齷黎齝鶮鵬鵫麻麹麸齌齊鸗齹鯴麵黝麠鯜鯚鸒鸑黝麠麹麸鱛齴鮿鵬鵫鶱黖鶙黒鴜齹黝鴺鸒鸑龉龅鯴鹿鹾黐鵬鵫龎麹麸齌齊鸗齹齚鼟鼁鼞鵬鵫鼚鸒鸑龉龅鯴鹿鹾黐鵬鵫龎麹麸齌齊鸗齹鼧黫齝龶 $form['#validate'] 齠龁龀龎麹麸齌齊鸗齹鳭鳫麠黐齹 $form['#validate'] 麶麒齝鰷鱶鸛齐龎龉龅鮮鳰龎麹麸齌齊鸗齹龉龅龘鼢鶱鶕鱧鱥鬇鱫龉龅麕鹜龎 validateForm 鸃鸂鴒鵌麶麒齠齹麹麸鶘黎齠鯐齴鼵鸻鸸鹠鶕鶑鸒鸑齍

黖黐鼤鴒龎鳍鹿鹾麹麸鸗鹁鯓鳇鹿鹾麹麸鸗鹁龉龅鯴鹿鹾麹麸鸗鹠黚黖龶龉龅麕鹜龎 buildForm 鸃鸂齠鵬鵫齹鰒鰐黚黖龶鳄鳃鳏齠鵬鵫齹鵂鵁龉龅麕鹜龎 validateForm 鸃鸂麮鵴鶑龘鼢鱧鱥鱫鸍鴒 $form['#validate'] 齠齹鲅黖鲸鲶黝鳱龶鵬鵫鹦齍

龶鲅鼞龎鹿鹾鳡魯鯴鹿鹾齠齹齚鼟鵬鵫麻 #needs_validation 鱃鰿齹黿黼鶭麻鸒鸑麹麸齌齊鸗黜齹鷷鶱鯍鸑鳱鱾龎鲳黜麹麸齅驊驭齝鶮骟髋鶉齹鼤鸜龎鴿鵸齝鶮龶鴚鴿鷓齠

黚黖龶鼤鼣鯓鳇鹿鹾黐龑鵬鵫 #limit_validation_errors 鱃鰿黖髋鶉麹麸鼛鼊齹鵌鱃鰿齝齴鼵麶麒齹黎齠鹿鹾齝黝鶆麃鶑髊鶉麹麸鼛鼊龎龉龅鹿鹾龎 #parents 鱃鰿麶麒齹龶黧鼵麶麒齠龎鹿鹾黖黜龎鹿鹾鷏髅麹麸鳇鰫鼛鼊齹黠鶕鶑骨骤齹鬐鬏鬎麤龘鼢黆龶驉鵌麶麒齠龎鹿鹾龎鼛鼊鸞鸝齹齚鼟黒鯣麶麒齹黿黼黝龶驉黣齗鼛鼊齹鷐鸽麣黝鶑麹麸鱛龶齇鶦齠鵌鷓鶑齌齊鼧鳿鳻鼑 $form_state->limit_validation_errors 鱃鰿齹鼧黫黆鴾齝 NULL 黯麶麒齹鴏鰻麣 NULL 鶱鸥鸡鲅鼞鼛鼊齹黧齝鹦龎鵹黓鷓齹齚鼟黒麶麒齹黿黼黆鼞龶黎齠龎鹿鹾骹鸥鸡鼛鼊齹鯣麶麒鵧 [] 鵣鶱黝鸥鸡黣齗鼛鼊齹齚鼟黝黒鯣麶麒黿黼鵌麶麒龎鹿鹾齝龉龅鹿鹾龎 #parents 鱃鰿麶麒齹龉齿鹦鴰龉龎鹿鹾鶱鶕鸥鸡鼛鼊齹麱黎鳧龎黝鶕鶑鸥鸡鼛鼊齍

麹麸黸黵鼧齚鼟鼞鼛鼊鶱齓鸑龉龅鼛鼊齌齊鸗齹鶁黐齍

麹麸鼧鲢鷱齴鼵鹿鹾龎鼛鼊齝鲦鹦龎 #parents 麶麒齠龎魫魨鹿鹾鹹鰤驙鬅鮛鱽齹鱽鴒鷏鳒鸻齍

龉龅鼛鼊齌齊鸗齅

鳫鸗 id form_error_handler

鵊齅 Drupal\Core\Form\FormErrorHandler

鶣鸋齅 \Drupal\Core\Form\FormErrorHandlerInterface

鵌齌齊鸗黖鳫鸗鵏鵎龎鸃鶜龁龀齹鸽龉龅麹麸鳇鳔鼞鼛鼊龎鶘鬙齹黒龉龅麶麒鬤齠龎鯐齴鼵鹿鹾鷣驆黖 # 鹹鰤龎鲿鲂齹鼧鶟鹿鹾齹鳡魯龉龅鰷黜魨鹿鹾鷟龁龀 '#children_errors' '#errors' 鱃鰿齹鯰齐驯驭鯀龚龎鳻鯽驵驳驩鸂齍

黆麃鼍鳔齴鼵鼛鼊齹鬐鬏鬎麤鵒齝 $form_state->getErrors() 黒骰鷓齹黿黼鲅鼞龎龉龅鹿鹾鹠鶕鶑鵬龁龀 '#errors' 鱃鰿齹鷏鸛鵌鹿鹾鼁鼞鼛鼊黠鶕鶑龁龀齹鼁鼞鼛鼊鶘黒鯣鷓齹鼞鷓鶘鴰龉鹿鹾龱驅鼍鳔龎鼛鼊齹黒 $form_state->getError($elements) 鳒鸻龎鷓齍

鱃鰿 #children_errors 龶鲅鼞驆驥鳍驤鮒齠鶑龁龀齹鹦鴰龉齴鼵驤鮒鹿鹾龎鲅鼞鶥鶣鳍鹿鹾鮰黎鼧鴰鹿鹾齠鼍鳔龎鼛鼊鷣鼧鼢鶟黒鳍鹿鹾鷟齹齚鼟鼁鼞鼛鼊齹黿黼黒鯣麶麒齹鶮鼚齝齴鼵鸟驄麶麒齹鲿鲂黒黖鳇鰫鼛鼊龎鳍鹿鹾龎 #array_parents 龎鷓黖鵧 ][ 鵣驂鶣龎鮌魹魵齹鵌鮌魹魵龶龉龅麶麒齠鴾騿齴鶵鶴鵌鳍鹿鹾齹鲿鷓黒龦魾髹髸龎 '#errors' 鱃鰿龎鷓齹騾騾齝齴鼵 Markup 麕鹜鱛

鴔黂黒龉龅鹿鹾鵬鵫 '#children_errors' '#errors' 鱃鰿鵒鴾龶齐鼲鬁龑齠鴜鯗鶵鶴鼛鼊麻齹黧鼞鼵鶆麃鵂鵁龎鸈鸃齹黿鵒齝麒鹿鹾齹齚齅 containers details fieldgroups fieldsets 齹鳧鲶龶龉龅麶麒齠黚黖黝鯜驠鯈鳍鸟龘鬨鳔齹麱齝龶鳍鹿鹾齠鵬鵫 '#group' 鱃鰿黖鵼龁鲅龶龎鴄麒齹鲅黖龶驵驳龉龅鶘鼑騻麻鲍鳰齌齊齹騹麒鹿鹾黠鴾鲢鲙鷋鯗龎 '#children_errors' 鱃鰿齹黧黚黖騹鳍鹿鹾鼍鳔鼛鼊鶘齹麒鹿鹾龶鼹齿鶘鱧鱥鹻鹹齍

鼤鼣齌齊鸗齅

龘鼢龶黖鼻鵏鵎齠鯍鸑龉龅鼤鼣鴶鴵齅

鵏鵎 id form_submitter

鵊齅 Drupal\Core\Form\FormSubmitter

鶣鸋齅 \Drupal\Core\Form\FormSubmitterInterface

龉龅鼤鼣齌齊黑麹麸齌齊黝麠龎齝黝鶕鯍鸑龉龅驵驳齹黑黎鵊騷龎齝黚黖龶鼤鼣鯓鳇鹿鹾黐龑鵬鵫鼤鼣齌齊鸗齹黧鶱鱟鱞黝麠龎鼤鼣鯜鯚鸒鸑黝麠龎鼤鼣齌齊齹黠黚黖龶龉龅鯴鹿鹾黐龑鵬鵫鼤鼣齌齊鸗齹鲺鲱齌齊鸗鹠齝鴔黂 #submit 鱃鰿鯍鸑齹黎鷓黒齴鼵鹍齴鼵黯麿鼵鼤鼣齌齊鸗鸻鸸鸙黵龎麶麒齹鸻鸸鴪麶黒黖鰊齐鸃鶜鳿鳻龎 $form $form_state 鱛鵬鵫鼤鼣齌齊鸗黚黖龶龉龅麕鹜龎 buildForm 鸃鸂齠鯍鸑齹鰒鰐黚黖鴔黂鳏鳍鵬鵫鱛齚鼟鯓鳇鹿鹾鵬鵫麻鼤鼣齌齊鸗齹黿黼鶱黝鶕鴺鸛齐龉龅鯴鹿鹾黐鵬鵫龎鼤鼣齌齊鸗齹鶮鼚鶱鸒鸑龉龅鯴鹿鹾黐鵬鵫龎鼤鼣齌齊鸗齹龘鼢鶕鱧鱥鶱龉龅麕鹜龎 submitForm 鸃鸂鵬鵫鴒龉龅鯴鹿鹾黐齹黧黠齝鲸鲶鰷鱶鸛齐龎齌齊鸗齹黝鳱鴺鬅鵬鵫齍

麹麸鴶鴵驐龚驌鮛龉龅齝鶮鼤鼣齹齐 $form_state->isSubmitted() 鷫鳰齹鹦龉齿齴鼵龉龅齝鶮麮鵴鼤鼣麻齹麱黝齝鵼齝鶮麮鵴鼤鼣鼔齌齊麻齹齌齊黸黵鼧鶕鵬鵫 $form_state->setExecuted(); 齹鲅黖 $form_state->isExecuted() 骹龉齿麮鵴齌齊麻齍

龶鼤鼣齌齊鸗齠黚黖鴔黂 $form_state->setResponse(Response $response) 鵬鵫齴鼵黳黲麕鹜齹龉齿龉龅齌齊鬣騶鼧鳒鸻鵌黳黲齹齚鼟鼞麿鼵齌齊鸗齹黿黼黖鰷鼧齴鼵龎鵬鵫黒鴜齹黧鳶鶆麃鵂鵁鵌黳黲龶鶌鶉鸗齠黖鱹鱶鸃鶜鱺鼍齹麎鼵龘鼢鯍鸍鱹鱶齌齊齈齇齹龶 \Symfony\Component\HttpKernel\HttpKernel 齠鰷騳鶕黨騱鼲魓鳒鸻鵌黳黲齍

齌齊鸗黠黚黖鵬鵫齴鼵鼙龁黨齹鸃鸂黒齅

$form_state->setRedirect($route_name, array $route_parameters = [], array $options = [])

黯黫齅

$form_state->setRedirectUrl(Url $url)

麠黇齚鼟鼞麿鼵齌齊鸗齹黿黼黖鰷鼧齴鼵龎鵬鵫黒鴜齹齚鼟黳黲黑鼙龁黨麠鶘鵬鵫齹黿黼黖黳黲黒鴜齹齚鼟騭黫鹠鼁鼞鵬鵫黿黼鶱黖 303 鸶鸵龎黳黲鼙龁黨鴒鸽龦驂鶣齹黧鲱鼙龁黨黳黲黠齝鴔黂鹥鹡龎鱹鱶齌齊齈齇鳒鸻鼑鶪鶨鸗龎齍

騧齌齊鶣鸋齅

鶁鷐鸟龮龪

鶪鶨鸗龉龅鼤鼣鸑黒齅

龶騤騣鹁 chrome Edge IE 齠騠騝鼞齚鼻鬣鼟齅

鶑鶵鸥黒鯅齐龎鷦鸍鹿鹾鷣 disabled="disabled" 鷟黝鶕鶑鶪鶨鸗鼤鼣鱛

鼞麿鼵鼤鼣鯜鯚鶘齹黆鼞鶑鮒鮏鯓鳇龎鼤鼣鯜鯚鷓鶑鼤鼣鱛

鼁鼞鴿騚黣齗鷓龎 select radio checkbox 黝鶕鶑鼤鼣鱛

鼙鵫鯜鯚黝鶕鶑鼤鼣鱛

鯜鯚鵊骬龎 input 黝鶕鶑鼤鼣齹鲏黠黝鶕鯓鳇龉龅鼤鼣鸑黒齹鶭驆鼞 js 騗髻鱛

鷣黖黐黝鶕鶑鼤鼣龎鵁騔齝 $_POST 齠鳝鶙鲿鲂

text 鵊骬龎 input 鷏鸛鼁鼞鷦鸍麮鶕鶑鼤鼣齹鶙鶘鷓黒鴏鰻麣‘’龎 string 鵊骬鷓齹黠鵒齝齴鼵鯣鮌魹魵鷓齍

龶龉龅鼁鼞鷓鶘鴤麿鶪鶨鸗鶕鸛齐鱧鱥黸黵鷣鶱黖龦齐黂龎鷓鱧鱥鼯鸾黐鲩鷟齹鴌鶪鶨鸗龎鵹黓鸑黒黝齴黇鷣 chrome 騑黨麣黝鼯鼫齹黎鳧騑黨麣鼯鼫鷟齹黧黚鴾鳝鵁齠騍騉鼛鼊齹齚鳝鲍鳰鶆麃騅騂鵬鵫 autocomplete="off" 黖駾駻黧鼵鶍龪齍

龉龅鼤鼣鹿鹾龎 name 鷓黚黖齝麶麒駸鶜齹黝鯁齝齴魤麶麒齹黚黖齝黣鵁麿魤龎麶麒齹鵌鲍鰿鱟鱞鶱麿鼵龉龅鷦鸍鹿鹾鷣黝麃鲤齝麠鵊骬鹿鹾鷟龎鷓驕鼔鼤鼣鴒齴鼵 $_POST 鲿鲂齠齹齚鼻龔鳍齅

<input name="choose['a']" type="checkbox" value="选择" autocomplete="off" />
<select name="choose['b'][]" size="3" multiple="multiple"  autocomplete="off" >
  <option value="1">选择1</option>
  <option value="2">选择2</option>
  <option value="3">选择3</option>
</select>

鼤鼣鼧鶱鵊騷齚鼻齅

    [choose] => Array
        (
            ['a'] => 选择
            ['b'] => Array
                (
                    [0] => 2
                    [1] => 3
                )

        )

黧黠鵒齝龘鼢黒鹃黼鵬鵫 #parents 龎鰨鳕齹龶鼧魓鲸鲶黝鶆麃鷻麝龦魓鹿鹾龎鬣鸙齹黆鶆麃鷻麝鷓龎鬣鸙鷏黚齍黧鳶鶆麃鵂鵁齅

駯鴿鮂龎鲂鮌鶆麃齝麶麒駸鶜齹鶮鼚鶱黖鰷鼧齴鼵鷓鹝黒鼤鼣鷓

select 鹿鹾鱟鱞麿鴿鶘鷣鮻鴚 multiple="multiple" 鷟齹鲂鮌黠鶆麃齝麶麒駸鶜齹鶮鼚鶱黖鰷鼧齴鼵鷓鹝黒鼤鼣鷓

鵮鸾齅

  1. bug1 齅龶 \Drupal::formBuilder()->buildForm 鸃鸂齠鴪麶黝黲鵌鯰齐鰊齐鳿鳻齹鳕黒麕鹜鵹黓黖鰊齐鳿鳻齹黧鶕騍騉黖鼻鴰鱘鰮鰫鼛鼊鼤齿齅

\Drupal::formBuilder()->buildForm(new a(), new b());

bug2: 龶龉龅鰃鴀鵏鵎齠鳿鳻麻 page_cache_request_policy 鵏鵎鴭鸙鰲鴪麶齹鱔鯻鶑鸛齐

2 \Drupal\Core\Form\FormBuilder::getForm 黆鴾鶣鯺龉龅麕鹜黯黫黎鴏髋龁鵊鲂齹鲻鼪鵊鲮鲪鸗黚黖鶣鯺鵏鵎鲂齹鱔駮龦黝鴾鶱龉龅麕鹜龁龀黒鵏鵎鼪鼧鳿鳻鵏鵎鲂齍

3 鹁鼤鼣龉龅龎鸃鸂齝 get 鶘齹鵹黓黝齓齐 CSRF token 齹黧齝鳕黒 get 鲥鲤黝黲鵌鰮鰫驺鹝齐齹鲅黖鼁鼞麹麸龎鳱麃齹鱔齚鼞鲍鮅齀鼿黚黖龶龉龅麶麒齠鵼龁 #token 黖鵯鶉麹麸鷣龶龉龅麕鹜龎 buildForm 鸃鸂齠鵼龁 $form['#token'] = true; 鷟齹龘鼢鵹黓黆鼞黓麸駫鼲龎龉龅骹鶕鯍鸑 CSRF 麹麸

4 鹁龶 url 鰮鰫鸗齠鵧 <current> 鵣黚黖龉齿鸽龦鲥鲤鲅龶龎鶐鹍

5 鹁鵬鵫鴌齌齊鸗鸻鸸鶘齹齚鼟齝龉龅麕鹜鳶龑龎鸃鸂齹黿黼黖鵧 :: 鵣鹹鰤鱫鸃鸂鲂鷏黚

6 鹁齚鼟龶 uri 齠鼍鳔 \Drupal\Core\Form\FormBuilderInterface::AJAX_FORM_REQUEST 鴪麶鷣鵌鱶鷗龎鷓黒 'ajax_form' 鷟齹麤鰸鲥鲤齝齴鼵 Ajax 鲥鲤齹

7 鹁鵹黓龶龉龅鸙龢鸗齠鳤麊鳊鳇鸗鼁鼞鶑鸛齐

8 form_id base_form_id 龎鬊鳰齅

form_id 齐麣騿齴鶴鳰龉龅齹齐龶龮龪鳏鳍鹁龉龅鳄鳃鳏鳍鰻鰻鸈鸃齹 base_form_id 鹝黒鲒鱫龎 id 齹黚黖鱯鱫鲳黜龎龮龪鳏鳍黑鳄鳃鳏鳍

9 form_build_id form_id 龎鬊鳰齅

form_id 齅騿齴鶵鶴齴鼵龉龅

form_build_id 齅騿齴鶵鶴齴鼵齐鼲鷦鸍龎龉龅齹鯐鼵齐鼲鹠黝齴黇齹齐鹝鰃鴀 id

10 鹁鸽龦龉龅 api 龎黋鳔齠齹鼤鼣齌齊鼧龎黳黲黑鼙龁黨齝鴔黂 http 鹥鹡龎鱹鱶齌齊齈鯍鸑龎齹鼪麱鱹鱶鶌鶉黝黲鵌齐麣鷋鱶龎鴶鴵齈鶌鶉齹鲅黖鶱麦鵌鸑黒黚鴾鶕鼙鼕黋鳔

11 鹁龉龅鼤鼣龎 W3C 駟鸃駛駘齅

https://www.w3.org/TR/2017/REC-html52-20171214/sec-forms.html#forms-for…

本书共83小节:

评论 (1)