getPhpValues() 공개 메소드

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does.
public getPhpValues ( ) : array
리턴 array An array of field values
예제 #1
0
 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
0
 /**
  * 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
0
    /**
     * 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
0
 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
0
 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
0
 /**
  * @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
0
 /**
  * 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());
 }
 /**
  * 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
0
 /**
  * 
  * @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
0
파일: Client.php 프로젝트: Briareos/Undine
 /**
  * @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.
     });
 }