Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
BomAle Posted October 31, 2016 Posted October 31, 2016 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
bfarber Posted November 1, 2016 Posted November 1, 2016 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.
BomAle Posted November 2, 2016 Author Posted November 2, 2016 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.
BomAle Posted November 2, 2016 Author Posted November 2, 2016 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;
bfarber Posted November 2, 2016 Posted November 2, 2016 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' ) );
Recommended Posts
Archived
This topic is now archived and is closed to further replies.