當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DomCrawler\Form類代碼示例

本文整理匯總了PHP中Symfony\Component\DomCrawler\Form的典型用法代碼示例。如果您正苦於以下問題:PHP Form類的具體用法?PHP Form怎麽用?PHP Form使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Form類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: gotoPreviousFormPage

 /**
  * Go to the previous form page
  *
  * @param \Symfony\Component\DomCrawler\Form $form
  * @return \TYPO3\Flow\Http\Response
  */
 protected function gotoPreviousFormPage(\Symfony\Component\DomCrawler\Form $form)
 {
     $previousButton = $this->browser->getCrawler()->filterXPath('//nav[@class="form-navigation"]/*/*[contains(@class, "previous")]/button');
     $previousButton->rewind();
     $form->set(new InputFormField($previousButton->current()));
     return $this->browser->submit($form);
 }
開發者ID:kitsunet,項目名稱:form,代碼行數:13,代碼來源:AbstractFunctionalTestCase.php

示例2: testGetFormNode

 public function testGetFormNode()
 {
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><form><input type="submit" /></form></html>');
     $form = new Form($dom->getElementsByTagName('input')->item(0));
     $this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
 }
開發者ID:spf13,項目名稱:symfony,代碼行數:7,代碼來源:FormTest.php

示例3: makeRequestUsingForm

 protected function makeRequestUsingForm(Form $form)
 {
     $files = [];
     $plainFiles = $form->getFiles();
     foreach ($plainFiles as $key => $file) {
         $files[$key] = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error'], true);
     }
     return $this->makeRequest($form->getMethod(), $form->getUri(), $form->getValues(), [], $files);
 }
開發者ID:woolensculpture,項目名稱:pulse,代碼行數:9,代碼來源:IntegrationTestCase.php

示例4: isValid

 public function isValid(Form $form)
 {
     if ($form->has('token')) {
         $values = $form->getValues();
         $values['token'] = 'modified by csrf scanner';
         $form->setValues($values);
         $this->client->submit($form);
         $status = $this->client->getResponse()->getStatus();
         if (403 == $status) {
             return true;
         }
         $this->message = "403 response expected, but got a {$status}";
     } else {
         $this->message = "No 'token' input field found";
     }
     return false;
 }
開發者ID:goodhacker,項目名稱:marlon-csrfscanner,代碼行數:17,代碼來源:ModifyingTokenCauses403.php

示例5: createFromForm

 /**
  * @param Form $form
  *
  * @return ModuleList
  */
 public static function createFromForm(Form $form)
 {
     $node = new Crawler($form->getFormNode());
     // Example: <input type="checkbox" id="edit-modules-other-oxygen-enable" name="modules[Other][oxygen][enable]" value="1" class="form-checkbox" />
     $inputs = $node->filter('input[type="checkbox"][id^="edit-modules-"]');
     $modules = [];
     foreach ($inputs as $input) {
         /** @var \DOMElement $input */
         if (!$input->hasAttribute('name')) {
             continue;
         }
         $enabled = $input->hasAttribute('checked');
         $match = preg_match('{^modules\\[([^\\]]+)\\]\\[([^\\]]+)\\]\\[enable\\]$}', $input->getAttribute('name'), $matches);
         if (!$match) {
             continue;
         }
         list(, $package, $slug) = $matches;
         $modules[] = new ModuleListItem($package, $slug, $enabled);
     }
     return new self($modules);
 }
開發者ID:Briareos,項目名稱:Undine,代碼行數:26,代碼來源:ModuleList.php

示例6: mergeForms

 /**
  * Merges second form values into first one.
  *
  * @param Form $to   merging target
  * @param Form $from merging source
  */
 private function mergeForms(Form $to, Form $from)
 {
     foreach ($from->all() as $name => $field) {
         $fieldReflection = new \ReflectionObject($field);
         $nodeReflection = $fieldReflection->getProperty('node');
         $valueReflection = $fieldReflection->getProperty('value');
         $nodeReflection->setAccessible(true);
         $valueReflection->setAccessible(true);
         $isIgnoredField = $field instanceof InputFormField && in_array($nodeReflection->getValue($field)->getAttribute('type'), array('submit', 'button', 'image'), true);
         if (!$isIgnoredField) {
             $valueReflection->setValue($to[$name], $valueReflection->getValue($field));
         }
     }
 }
開發者ID:penguinclub,項目名稱:penguinweb_drupal8,代碼行數:20,代碼來源:BrowserKitDriver.php

示例7: testSubmitWithoutAFormButton

 public function testSubmitWithoutAFormButton()
 {
     $dom = new \DOMDocument();
     $dom->loadHTML('
         <html>
             <form>
                 <input type="foo" />
             </form>
         </html>
     ');
     $nodes = $dom->getElementsByTagName('form');
     $form = new Form($nodes->item(0), 'http://example.com');
     $this->assertSame($nodes->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:14,代碼來源:FormTest.php

示例8: getSonataAdminFormName

 public function getSonataAdminFormName(Form $form)
 {
     parse_str(parse_url($form->getUri(), PHP_URL_QUERY), $query);
     return $query['uniqid'];
 }
開發者ID:ruslan-polutsygan,項目名稱:dev-bundle,代碼行數:5,代碼來源:SonataAdminExtensionTrait.php

示例9: submitEditForm

 /**
  * Edits the data of a form
  *
  * @param  Client $client
  * @param  Form   $form
  * @param  array  $data
  */
 protected function submitEditForm(Client $client, Form $form, array $data = array())
 {
     $originalData = array();
     foreach ($form->all() as $fieldName => $formField) {
         $originalData[$fieldName] = $formField->getValue();
     }
     $data = array_merge($originalData, $data);
     $this->submitForm($client, $form, $data);
 }
開發者ID:biggtfish,項目名稱:forkcms,代碼行數:16,代碼來源:WebTestCase.php

示例10: fillFormForUpdateTest

 /**
  * Fill form for address tests (update test)
  *
  * @param Form $form
  * @return Form
  */
 protected function fillFormForUpdateTest(Form $form)
 {
     $formNode = $form->getNode();
     $formNode->setAttribute('action', $formNode->getAttribute('action') . '?_widgetContainer=dialog');
     $form['orob2b_account_typed_address[types]'] = [AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING];
     $form['orob2b_account_typed_address[defaults][default]'] = [false, AddressType::TYPE_SHIPPING];
     $doc = new \DOMDocument("1.0");
     $doc->loadHTML('<select name="orob2b_account_typed_address[country]" id="orob2b_account_typed_address_country" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="ZW">Zimbabwe</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $form['orob2b_account_typed_address[country]'] = 'ZW';
     $doc->loadHTML('<select name="orob2b_account_typed_address[region]" id="orob2b_account_typed_address_region" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="ZW-MA">Manicaland</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $form['orob2b_account_typed_address[region]'] = 'ZW-MA';
     return $form;
 }
開發者ID:adam-paterson,項目名稱:orocommerce,代碼行數:23,代碼來源:AccountAddressControllerTest.php

示例11: submitForm

 /**
  * @param Form $form
  *
  * @return Crawler
  */
 protected function submitForm(Form $form)
 {
     $action = $form->getFormNode()->getAttribute('data-action');
     $form->getFormNode()->setAttribute('action', $action);
     return $this->client->submit($form);
 }
開發者ID:open-orchestra,項目名稱:open-orchestra,代碼行數:11,代碼來源:AbstractFormTest.php

示例12: convertUploadsForTesting

 /**
  * Convert the given uploads to UploadedFile instances.
  *
  * @param  \Symfony\Component\DomCrawler\Form  $form
  * @param  array  $uploads
  * @return array
  */
 protected function convertUploadsForTesting(Form $form, array $uploads)
 {
     $files = $form->getFiles();
     $names = array_keys($files);
     $files = array_map(function (array $file, $name) use($uploads) {
         return isset($uploads[$name]) ? $this->getUploadedFileForTesting($file, $uploads, $name) : $file;
     }, $files, $names);
     $uploads = array_combine($names, $files);
     foreach ($uploads as $key => $file) {
         if (preg_match('/.*?(?:\\[.*?\\])+/', $key)) {
             $this->prepareArrayBasedFileInput($uploads, $key, $file);
         }
     }
     return $uploads;
 }
開發者ID:laravel,項目名稱:framework,代碼行數:22,代碼來源:InteractsWithPages.php

示例13: getFormValuesFor

 /**
  * Returns an array of name => value pairs for the passed form.
  *
  * For form fields containing a name ending in [], an array is
  * created out of all field values with the given name.
  *
  * @param \Symfony\Component\DomCrawler\Form the form
  * @return array an array of name => value pairs
  */
 protected function getFormValuesFor(Form $form)
 {
     $values = [];
     $fields = $form->all();
     foreach ($fields as $field) {
         if ($field->isDisabled() || !$field->hasValue() || $field instanceof FileFormField) {
             continue;
         }
         $fieldName = $this->getSubmissionFormFieldName($field->getName());
         if (substr($field->getName(), -2) === '[]') {
             if (!isset($values[$fieldName])) {
                 $values[$fieldName] = [];
             }
             $values[$fieldName][] = $field->getValue();
         } else {
             $values[$fieldName] = $field->getValue();
         }
     }
     return $values;
 }
開發者ID:vladislavl-hyuna,項目名稱:crmapp,代碼行數:29,代碼來源:InnerBrowser.php

示例14: getFormValuesFor

 /**
  * Returns an array of name => value pairs for the passed form.
  *
  * The function calls getPhpValues on the passed form object, then
  * resets numeric array indexes for array field names without array
  * keys specified (i.e. 'fieldname[]' but not 'fieldname[keyname]')
  * as expected by setCheckboxBoolValues.
  *
  * @param \Symfony\Component\DomCrawler\Form the form
  * @return array an array of name => value pairs
  */
 protected function getFormValuesFor(Form $form)
 {
     $values = $form->getPhpValues();
     $fields = $form->all();
     foreach ($fields as $field) {
         $name = $this->getSubmissionFormFieldName($field->getName());
         if (!empty($values[$name]) && substr($field->getName(), -2) === '[]') {
             $values[$name] = array_values($values[$name]);
         }
     }
     return $values;
 }
開發者ID:alexanderkuz,項目名稱:test-yii2,代碼行數:23,代碼來源:InnerBrowser.php

示例15: submitForm

 /**
  * 
  * @param \Symfony\Component\DomCrawler\Form $form
  * @param string    $method     The Request Method
  */
 public function submitForm(Form $form, $method = "POST")
 {
     $this->getClient()->request($method, $form->getUri(), $form->getPhpValues());
 }
開發者ID:doyolabs,項目名稱:symfony-test,代碼行數:9,代碼來源:WebTestCase.php


注:本文中的Symfony\Component\DomCrawler\Form類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。