本文整理汇总了PHP中Symfony\Component\DomCrawler\Form::getPhpValues方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getPhpValues方法的具体用法?PHP Form::getPhpValues怎么用?PHP Form::getPhpValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Form
的用法示例。
在下文中一共展示了Form::getPhpValues方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testgetPhpValuesWithEmptyTextarea
public function testgetPhpValuesWithEmptyTextarea()
{
$dom = new \DOMDocument();
$dom->loadHTML('
<html>
<form>
<textarea name="example"></textarea>
</form>
</html>
');
$nodes = $dom->getElementsByTagName('form');
$form = new Form($nodes->item(0), 'http://example.com');
$this->assertEquals($form->getPhpValues(), array('example' => ''));
}
示例2: 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;
}
示例3: submit
/**
* Submits a form.
*
* @param Form $form A Form instance
* @param array $values An array of form field values
*
* @api
*/
public function submit(Form $form, array $values = array())
{
$form->setValues($values);
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles());
}
示例4: testConstructorHandlesFormAttribute
public function testConstructorHandlesFormAttribute()
{
$dom = new \DOMDocument();
$dom->loadHTML('
<html>
<form id="form_1" action="" method="POST">
<input type="checkbox" name="apples[]" value="1" checked />
<input form="form_2" type="checkbox" name="oranges[]" value="1" checked />
<input form="form_1" type="hidden" name="form_name" value="form_1" />
<input form="form_1" type="submit" name="button_1" value="Capture fields" />
<button form="form_2" type="submit" name="button_2">Submit form_2</button>
</form>
<input form="form_1" type="checkbox" name="apples[]" value="2" checked />
<form id="form_2" action="" method="POST">
<input type="checkbox" name="oranges[]" value="2" checked />
<input type="checkbox" name="oranges[]" value="3" checked />
<input form="form_2" type="hidden" name="form_name" value="form_2" />
<input form="form_1" type="hidden" name="outer_field" value="success" />
<button form="form_1" type="submit" name="button_3">Submit from outside the form</button>
</form>
<button />
</html>
');
$inputElements = $dom->getElementsByTagName('input');
$buttonElements = $dom->getElementsByTagName('button');
// Tests if submit buttons are correctly assigned to forms
$form1 = new Form($buttonElements->item(1), 'http://example.com');
$this->assertSame($dom->getElementsByTagName('form')->item(0), $form1->getFormNode(), 'HTML5-compliant form attribute handled incorrectly');
$form1 = new Form($inputElements->item(3), 'http://example.com');
$this->assertSame($dom->getElementsByTagName('form')->item(0), $form1->getFormNode(), 'HTML5-compliant form attribute handled incorrectly');
$form2 = new Form($buttonElements->item(0), 'http://example.com');
$this->assertSame($dom->getElementsByTagName('form')->item(1), $form2->getFormNode(), 'HTML5-compliant form attribute handled incorrectly');
// Tests if form elements are correctly assigned to forms
$values1 = array('apples' => array('1', '2'), 'form_name' => 'form_1', 'button_1' => 'Capture fields', 'outer_field' => 'success');
$values2 = array('oranges' => array('1', '2', '3'), 'form_name' => 'form_2', 'button_2' => '');
$this->assertEquals($values1, $form1->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
$this->assertEquals($values2, $form2->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
}
示例5: testConstructorHandlesFormValues
public function testConstructorHandlesFormValues()
{
$dom = $this->createTestHtml5Form();
$inputElements = $dom->getElementsByTagName('input');
$buttonElements = $dom->getElementsByTagName('button');
$form1 = new Form($inputElements->item(3), 'http://example.com');
$form2 = new Form($buttonElements->item(0), 'http://example.com');
// Tests if form values are correctly assigned to forms
$values1 = array('apples' => array('1', '2'), 'form_name' => 'form-1', 'button_1' => 'Capture fields', 'outer_field' => 'success');
$values2 = array('oranges' => array('1', '2', '3'), 'form_name' => 'form_2', 'button_2' => '', 'app_frontend_form_type_contact_form_type' => array('contactType' => '', 'firstName' => 'John'));
$this->assertEquals($values1, $form1->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
$this->assertEquals($values2, $form2->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
}
示例6: addMenuItemForm
/**
* @param Form $form
* @param $code
* @param $elementId
* @return Crawler
*/
private function addMenuItemForm(Form $form, $code, $elementId)
{
$ajaxClient = static::createClient();
$ajaxCrawler = $ajaxClient->request('POST', '/admin/core/append-form-field-element', array_merge($form->getPhpValues(), array('code' => $code, 'elementId' => 'page_' . $elementId, 'uniqid' => 'page')));
foreach ($ajaxCrawler->filter('input') as $node) {
if ($node->attributes->getNamedItem('type')) {
if ($node->attributes->getNamedItem('type')->nodeValue == 'checkbox' || $node->attributes->getNamedItem('type')->nodeValue == 'radio') {
$form->set(new ChoiceFormField($node));
continue;
}
if ($node->attributes->getNamedItem('type') == 'file') {
$form->set(new FileFormField($node));
continue;
}
}
$form->set(new InputFormField($node));
}
foreach ($ajaxCrawler->filter('select') as $node) {
$form->set(new ChoiceFormField($node));
}
foreach ($ajaxCrawler->filter('textarea') as $node) {
$form->set(new TextareaFormField($node));
}
return $ajaxCrawler;
}
示例7: makeRequestUsingForm
/**
* Make a request to a URL using form parameters.
*
* @param Form $form
* @return static
*/
protected function makeRequestUsingForm(Form $form)
{
return $this->makeRequest($form->getMethod(), $form->getUri(), $form->getPhpValues(), [], $form->getFiles());
}
示例8: submit
/**
* Submit a form
*
* @param \Symfony\Component\DomCrawler\Form $form
* @return \TYPO3\Flow\Http\Response
* @api
*/
public function submit(Form $form)
{
return $this->request($form->getUri(), $form->getMethod(), $form->getPhpValues(), $form->getPhpFiles());
}
示例9: 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());
}
示例10: disableModuleAsync
/**
* @param Form $form
* @param string $package
* @param string $slug
* @param Session $session
*
* @return Promise
*
* @rejects RequestException
*/
public function disableModuleAsync(Form $form, $package, $slug, Session $session)
{
$formData = $form->getPhpValues();
if (empty($formData['modules'][$package][$slug]['enable'])) {
// The module is already disabled.
return new FulfilledPromise(null);
}
unset($formData['modules'][$package][$slug]['enable']);
return $this->client->requestAsync($form->getMethod(), $form->getUri(), [RequestOptions::COOKIES => $session->getCookieJar(), RequestOptions::AUTH => $session->getAuthData(), RequestOptions::FORM_PARAMS => $formData, RequestOptions::HEADERS => ['referer' => $form->getUri()], RequestOptions::ALLOW_REDIRECTS => false])->then(function () {
// Resolve to null.
});
}