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…

本书共71小节:

评论 (1)