Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted October 31, 20168 yr I have tested some time this field but when try to get submitted values the result is not as expected. //<?php $type = new \IPS\Helpers\Form\Select( 'where[0][]', NULL, FALSE, array( 'options' => array( 'include' => 'include', 'exclude' => 'exclude' ) ) ); $location = new \IPS\Helpers\Form\Stack( 'where[1][]', array(), FALSE, array(), function($val){ if ( $val ) { foreach ( array_filter( is_array( $val ) ? $val : array( $val ) ) as $s ) { try { $s = (mb_substr( $s, 0, mb_strlen( \IPS\Http\Url::baseUrl() ) ) === \IPS\Http\Url::baseUrl() OR filter_var( $s, FILTER_VALIDATE_URL ) !== FALSE) ? $s : \IPS\Http\Url::baseUrl() . $s; $url = \IPS\Http\Url::createFromString( str_replace('*','',$s), TRUE, TRUE ); if ( !( $url instanceof \IPS\Http\Url\Internal) ) { throw new \InvalidArgumentException( $s ); } } catch ( \InvalidArgumentException $e ) { throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'ba_cta_popup_stack_err', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) ) ); } } } }); $form->add( new \IPS\Helpers\Form\Custom( 'where', array(), FALSE, array( 'getHtml' => function( $element ) use ($type,$location) { return $type->html() . $location->html(); } ), NULL, NULL, NULL, 'where' ) ); if ( $values = $form->values() ) { echo "VAR_DUMP \$_REQUEST['where']"; var_dump($_REQUEST['where']); echo "\n\n\nVAR DUMP \$values['where']"; var_dump($values['where']); exit; } return $form; consider old bug reports: @Matt @Andy Millne @Ali Majrashi
November 1, 20168 yr I'm fairly certain the stack javascript is designed to swap out the input element's name array keys, however it is not designed to work with sub (or sub-sub, etc.) arrays. In short, I'd stop trying to use a name like "where[1][]" and just use a unique form field name like "where_stack" or whatever. If that doesn't work please run the same test and let me know what you are seeing.
November 2, 20168 yr Author i don't remember but if i include input with different name (like where_first and where_two..) from Form\Custom name (where) the values submitted don't are present other different from "where" name.
November 2, 20168 yr Author see code below. //<?php $type = new \IPS\Helpers\Form\Select( 'where_one', NULL, FALSE, array( 'options' => array( 'include' => 'include', 'exclude' => 'exclude' ) ) ); $location = new \IPS\Helpers\Form\Stack( 'where_two', array(), FALSE, array(), function($val){ if ( $val ) { foreach ( array_filter( is_array( $val ) ? $val : array( $val ) ) as $s ) { try { $s = (mb_substr( $s, 0, mb_strlen( \IPS\Http\Url::baseUrl() ) ) === \IPS\Http\Url::baseUrl() OR filter_var( $s, FILTER_VALIDATE_URL ) !== FALSE) ? $s : \IPS\Http\Url::baseUrl() . $s; $url = \IPS\Http\Url::createFromString( str_replace('*','',$s), TRUE, TRUE ); if ( !( $url instanceof \IPS\Http\Url\Internal) ) { throw new \InvalidArgumentException( $s ); } } catch ( \InvalidArgumentException $e ) { throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'ba_cta_popup_stack_err', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) ) ); } } } }); $form->add( new \IPS\Helpers\Form\Custom( 'where', array(), FALSE, array( 'getHtml' => function( $element ) use ($type,$location) { return $type->html() . $location->html(); } ), NULL, NULL, NULL, 'where' ) ); if ( $values = $form->values() ) { echo "VAR_DUMP \$_REQUEST"; var_dump($_REQUEST); echo "\n\n\nVAR DUMP \$values"; var_dump($values); exit; } return $form;
November 2, 20168 yr Try this instead: $form->add( new \IPS\Helpers\Form\Custom( 'where', array(), FALSE, array( 'getHtml' => function( $element ) use ($type,$location) { return $type->html() . $location->html(); }, 'formatValue' => function( $element ) use( $type, $location ) { return array( 'where_one' => $type::stringValue( $type->value ), 'where_two' => $location::stringValue( $location->value ) ); } ), NULL, NULL, NULL, 'where' ) );
Archived
This topic is now archived and is closed to further replies.