Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Helpers\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -61,6 +61,11 @@ abstract class _FormAbstract
|
||||
* @brief Appears Required?
|
||||
*/
|
||||
public $appearRequired = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Additional CSS classnames to use on the row
|
||||
*/
|
||||
public $rowClasses = array();
|
||||
|
||||
/**
|
||||
* @brief Type-Specific Options
|
||||
@@ -130,14 +135,14 @@ abstract class _FormAbstract
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->required = is_null( $required ) ? FALSE : $required;
|
||||
$this->appearRequired = is_null( $required ) ? TRUE : $required;
|
||||
$this->required = \is_null( $required ) ? FALSE : $required;
|
||||
$this->appearRequired = \is_null( $required ) ? TRUE : $required;
|
||||
$this->options = array_merge( $this->defaultOptions, $options );
|
||||
$this->customValidationCode = $customValidationCode;
|
||||
$this->prefix = $prefix;
|
||||
$this->suffix = $suffix;
|
||||
$this->defaultValue = $defaultValue;
|
||||
$this->htmlId = preg_replace( "/[^a-zA-Z0-9\-_]/", "_", $id );
|
||||
$this->htmlId = $id ? preg_replace( "/[^a-zA-Z0-9\-_]/", "_", $id ) : NULL;
|
||||
|
||||
$this->setValue( TRUE );
|
||||
}
|
||||
@@ -234,6 +239,7 @@ abstract class _FormAbstract
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @param \IPS\Helpers\Form|null $form Form helper object
|
||||
* @return string
|
||||
*/
|
||||
public function rowHtml( $form=NULL )
|
||||
@@ -291,12 +297,12 @@ abstract class _FormAbstract
|
||||
/* Some elements support an array for suffix, such as Number which supports preUnlimited and postUnlimited. We need to wipe out
|
||||
the suffix here before calling the row() template, however, which only supports a string and throws an Array to string conversion error.
|
||||
By this point, the element template has already ran and used the suffix if designed to */
|
||||
if( is_array( $this->suffix ) )
|
||||
if( \is_array( $this->suffix ) )
|
||||
{
|
||||
$this->suffix = '';
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core' )->row( $label, $html, $desc, $warning, $this->appearRequired, $this->error, $this->prefix, $this->suffix, $this->htmlId ?: ( $form ? "{$form->id}_{$this->name}" : NULL ), $this, $form );
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core' )->row( $label, $html, $desc, $warning, $this->appearRequired, $this->error, $this->prefix, $this->suffix, $this->htmlId ?: ( $form ? "{$form->id}_{$this->name}" : NULL ), $this, $form, $this->rowClasses );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
@@ -318,7 +324,7 @@ abstract class _FormAbstract
|
||||
*/
|
||||
public function getLabelForAttribute()
|
||||
{
|
||||
return $this->name;
|
||||
return $this->htmlId ?? $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,7 +363,7 @@ abstract class _FormAbstract
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if( ( $this->value === '' OR ( is_array( $this->value ) AND empty( $this->value ) ) ) and $this->required )
|
||||
if( ( $this->value === '' OR ( \is_array( $this->value ) AND empty( $this->value ) ) ) and $this->required )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
@@ -366,13 +372,14 @@ abstract class _FormAbstract
|
||||
{
|
||||
if ( !static::utf8mb4Check( $this->value ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->isAdmin() ? 'form_multibyte_unicode_admin' : 'form_multibyte_unicode' );
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->isAdmin() ? ( \IPS\CIC ? 'form_multibyte_unicode_admin_cic' : 'form_multibyte_unicode_admin' ) : 'form_multibyte_unicode' );
|
||||
}
|
||||
}
|
||||
|
||||
if( $this->customValidationCode !== NULL )
|
||||
{
|
||||
call_user_func( $this->customValidationCode, $this->value );
|
||||
$validationFunction = $this->customValidationCode;
|
||||
$validationFunction( $this->value );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -384,9 +391,9 @@ abstract class _FormAbstract
|
||||
* @param mixed $value The value
|
||||
* @return bool
|
||||
*/
|
||||
protected static function utf8mb4Check( $value )
|
||||
public static function utf8mb4Check( $value )
|
||||
{
|
||||
if ( is_array( $value ) )
|
||||
if ( \is_array( $value ) )
|
||||
{
|
||||
foreach ( $value as $_value )
|
||||
{
|
||||
@@ -396,7 +403,7 @@ abstract class _FormAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( is_string( $value ) )
|
||||
elseif ( \is_string( $value ) )
|
||||
{
|
||||
return (bool) !preg_match( '/[\x{10000}-\x{10FFFF}]/u', $value );
|
||||
}
|
||||
@@ -411,11 +418,11 @@ abstract class _FormAbstract
|
||||
*/
|
||||
public static function stringValue( $value )
|
||||
{
|
||||
if ( is_array( $value ) )
|
||||
if ( \is_array( $value ) )
|
||||
{
|
||||
return implode( ',', array_map( function( $v )
|
||||
{
|
||||
if ( is_object( $v ) )
|
||||
if ( \is_object( $v ) )
|
||||
{
|
||||
return (string) $v;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user