本文整理匯總了PHP中Symfony\Component\DomCrawler\Form::getFormNode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::getFormNode方法的具體用法?PHP Form::getFormNode怎麽用?PHP Form::getFormNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DomCrawler\Form
的用法示例。
在下文中一共展示了Form::getFormNode方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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');
}
示例2: 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);
}
示例3: 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);
}
示例4: 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');
}
示例5: submit
private function submit(Form $form)
{
$formId = $this->getFormNodeId($form->getFormNode());
if (isset($this->forms[$formId])) {
$this->mergeForms($form, $this->forms[$formId]);
}
// remove empty file fields from request
foreach ($form->getFiles() as $name => $field) {
if (empty($field['name']) && empty($field['tmp_name'])) {
$form->remove($name);
}
}
foreach ($form->all() as $field) {
// Add a fix for https://github.com/symfony/symfony/pull/10733 to support Symfony versions which are not fixed
if ($field instanceof TextareaFormField && null === $field->getValue()) {
$field->setValue('');
}
}
$this->client->submit($form);
$this->forms = array();
}