public function addElementArray(array $elements) {

		if(count($elements)) {
			
			$firstElement = array_shift($elements);
			$name = $firstElement->getName();

			// remove any array indexes from name

			$name = preg_replace('~\[\w*\]$~i', '', $name);

			if(!empty($this->elements[$name])) {

				throw new HtmlFormException(sprintf("Element '%s' already assigned.", $name));

			}

			$arrayName = $name . '[]';
			$firstElement
				->setName($arrayName)
				->setForm($this)
			;

			$this->elements[$name] = [$firstElement];

			foreach($elements as $e) {
				
				if(get_class($e) !== get_class($firstElement)) {

					throw new HtmlFormException(sprintf("Class mismatch of form elements array. Expected '%s', found '%s'.", get_class($firstElement), get_class($e)));

				}
				
				// check whether names of element arrays match

				$nameToCheck = preg_replace('~\[\w*\]$~i', '', $e->getName());

				if($nameToCheck && $nameToCheck !== $name) {
					
					throw new HtmlFormException(sprintf("Name mismatch of form elements array. Expected '%s' or empty name, found '%s'.", $name, $e->getName()));

				}

				$e
					->setName($arrayName)
					->setForm($this)
				;

				$this->elements[$name][] = $e;
			}

		}

		return $this;

	}
public function addElementArray(array $elements) {

		if(count($elements)) {
			
			$firstElement = array_shift($elements);
			$name = $firstElement->getName();

			// remove any array indexes from name

			$name = preg_replace('~\[\w*\]$~i', '', $name);

			if(!empty($this->elements[$name])) {

				throw new HtmlFormException(sprintf("Element '%s' already assigned.", $name));

			}

			$arrayName = $name . '[]';
			$firstElement
				->setName($arrayName)
				->setForm($this)
			;

			$this->elements[$name] = [$firstElement];

			foreach($elements as $e) {
				
				if(get_class($e) !== get_class($firstElement)) {

					throw new HtmlFormException(sprintf("Class mismatch of form elements array. Expected '%s', found '%s'.", get_class($firstElement), get_class($e)));

				}
				
				// check whether names of element arrays match

				$nameToCheck = preg_replace('~\[\w*\]$~i', '', $e->getName());

				if($nameToCheck && $nameToCheck !== $name) {
					
					throw new HtmlFormException(sprintf("Name mismatch of form elements array. Expected '%s' or empty name, found '%s'.", $name, $e->getName()));

				}

				$e
					->setName($arrayName)
					->setForm($this)
				;

				$this->elements[$name][] = $e;
			}

		}

		return $this;

	}
public function addElementArray ( array $ elements ) { if ( count ( $ elements ) ) { $ firstElement = array_shift ( $ elements ) ; $ name = $ firstElement -> getName ( ) ; // remove any array indexes from name $ name = preg_replace ( '~\[\w*\]$~i' , '' , $ name ) ; if ( ! empty ( $ this -> elements [ $ name ] ) ) { throw new HtmlFormException ( sprintf ( "Element '%s' already assigned." , $ name ) ) ; } $ arrayName = $ name . '[]' ; $ firstElement -> setName ( $ arrayName ) -> setForm ( $ this ) ; $ this -> elements [ $ name ] = [ $ firstElement ] ; foreach ( $ elements as $ e ) { if ( get_class ( $ e ) !== get_class ( $ firstElement ) ) { throw new HtmlFormException ( sprintf ( "Class mismatch of form elements array. Expected '%s', found '%s'." , get_class ( $ firstElement ) , get_class ( $ e ) ) ) ; } // check whether names of element arrays match $ nameToCheck = preg_replace ( '~\[\w*\]$~i' , '' , $ e -> getName ( ) ) ; if ( $ nameToCheck && $ nameToCheck !== $ name ) { throw new HtmlFormException ( sprintf ( "Name mismatch of form elements array. Expected '%s' or empty name, found '%s'." , $ name , $ e -> getName ( ) ) ) ; } $ e -> setName ( $ arrayName ) -> setForm ( $ this ) ; $ this -> elements [ $ name ] [ ] = $ e ; } } return $ this ; }
add several form elements stored in array to form

the elements have to be of same type and have to have the same
name or an empty name

@param array FormElement[]
@throws HtmlFormException
@return \vxPHP\Form\HtmlForm
add several form elements stored in array to form