#1 2014-06-30 22:06:31

CodeStepper
Member
From: Poland
Registered: 2014-06-30
Posts: 53
Website

Tagmanager Form update

If I wrote in wrong thread, correct me smile
I make a simple correction for tag_form_error_value (applications/libraries/Tagmanager/Form.php).
Now it supports is="false" and <ion:else> tag.

Here's the code:

	public static function tag_form_error_value(FTL_Binding $tag)
	{
		$form_name = $tag->getParent( 'error' )->getParentName( );
		$is = $tag->getAttribute( 'is', NULL );
		
		if( is_null( $form_name ) && is_null( $is ) ) return '';
		if( $form_name != self::$posting_form_name && is_null( $is ) ) return '';
		
		// Validate or get the validation result
		self::validate( $form_name );
		
		$errors = !empty( self::$ci->form_validation->_error_array[$tag->name] );
		
		// Check "is" attribute
		if( !is_null( $is ) )
		{
			if( $errors == $is )
			{
				$return = $tag->getAttribute( 'return' );
				
				// Return the value asked by the "return" attribute
				if( !is_null( $return ) )
					return self::wrap( $tag, $return );
			
				// else...
				if( self::$trigger_else > 0 )
					self::$trigger_else--;
				
				// or expand the tag
				return self::wrap( $tag, $tag->expand( ) );
			}
			else
			{
				// else once again...
				self::$trigger_else++;
				return '';
			}
		}

		// Check errors
		if( !$errors ) return '';
		
		// At the end, it there is no "is" attribute, display error 
		return self::output_value( $tag, self::$ci->form_validation->_error_array[$tag->name] );
	}

Examples of use tags after this correction:

<ion:form:register:error:field is="true">
	IS TRUE
</ion:form:register:error:field>
<ion:else>
	IS FALSE
</ion:else>
<ion:form:register:error:field is="false">
	IS FALSE
</ion:form:register:error:field>

I have done it, because I needed this during creation registration form. smile

Redgards.

Last edited by CodeStepper (2014-07-01 14:02:20)

Offline

#2 2014-07-01 13:56:52

CodeStepper
Member
From: Poland
Registered: 2014-06-30
Posts: 53
Website

Re: Tagmanager Form update

Another update for tag_form_validation_error.
Now supports is="false" and else tag...

	public static function tag_form_validation_error(FTL_Binding $tag)
	{
		$key = $tag->getAttribute( 'key', NULL );
		$delimiter = $tag->getAttribute( 'delimiter', 'span' );
		$form_name = $tag->getParent( 'validation' )->getParentName( );
		$is = $tag->getAttribute( 'is', NULL );
		
		// 'additional_error' values
		$values = NULL;
		$fd = self::$ci->session->flashdata( $form_name );
		
		if( !empty( $fd['additional_error'] ) ) $values = $fd['additional_error'];
		else
		{
			// Adds additional errors to the CI Validation error array
			self::check_additional_errors( $form_name );
			
			if( self::$posting_form_name == $form_name )
			{
				// We're not in 'redirect mode' : Remove the flash session data
				self::$ci->session->unset_flashdata( $form_name );
				
				// Validate the form if it wasn't done
				self::validate( self::$posting_form_name );
				
				// No key : Get the string
				if( is_null( $key ) )
				{
					self::$ci->form_validation->set_error_delimiters( '<' . $delimiter . '>', '</' . $delimiter . '>' );
					$values = self::$ci->form_validation->error_string( );
				}
				else $values = self::$ci->form_validation->_error_array;
			}
		}
		
		// No errors, no "is" attribute
		if( is_null( $values ) && is_null( $is ) ) return '';
		
		// Expand mode
		if( !is_null( $is ) )
		{
			// Check "key" attribute
			$errors = (is_null( $key )) ? !empty( $values ) : !empty( $values[$key] );
			
			if( $errors == $is )
			{
				if( self::$trigger_else > 0 )
					self::$trigger_else--;
			
				return self::wrap( $tag, $tag->expand( ) );
			}
			else self::$trigger_else++;
		}
		// Output mode
		else if( is_null( $key ) )
		{
			if( !empty( $values ) )
			{
				$str = '';
				
				if( is_string( $values ) ) $values = array( $values );
				foreach( $values as $val ) $str .= '<span>' . $val . '</span>';
				
				return self::wrap( $tag, $str );
			}
		}
		else if( !empty( $values[$key] ) ) return self::wrap( $tag, $fd[$key] );
		
		return '';
	}

Examples of use tags after correction:

<ion:form:register:validation:error is="true">
	IS TRUE
</ion:form:register:validation:error>
<ion:else>
	IS FALSE
</ion:else>
<ion:form:register:validation:error is="false">
	IS FALSE
</ion:form:register:validation:error>

Last edited by CodeStepper (2014-07-01 14:00:24)

Offline

#3 2014-07-09 12:12:03

Michel-Ange
Ionize Core Team
From: Paris, France
Registered: 2010-03-22
Posts: 927
Website

Re: Tagmanager Form update

Thanks CodeStepper, we will test it and add it to the next release.


Inspiration & Innovation : Websites by Partikule, Agence Web Paris

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations