本文整理汇总了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();
}