my own css class

cuhuak 18 Apr, 2008
That is not bag, but chorocontact do not works correct.
If I specify a css-class of my control like this:

<input name="LastName" id="LastName" value="" maxlength="190" type="text" class="textInput" />

then I'll have output like this

<input name="LastName" class="required validate-alpha" id="LastName" value="" maxlength="190" type="text" class="textInput" />


We understand that it have to be something like this:

<input name="LastName" id="LastName" value="" maxlength="190" type="text" class="textInput required validate-alpha" />

where I have one class-attribute.

This issue have been solved by me... but today i have updated my Module, backuping my old version. Now I'll try to realize this feature at the current version.
If someone have
GreyHead 18 Apr, 2008
Hi cuhuak,

This is a known problem. The solution is not to add class statements directly to your form input tags. Instead use divs to wrap your code and use descendant selectors to add css.

Bob
cuhuak 21 Apr, 2008
Hi again. As sad i solved this problem.
Here is code of easy validation.
file: chronocontact.php
	if( trim($paramsvalues->validate) == 'Yes'){
	// Easy Validation //
			
			$pattern = '/ (name=["|\'](.*?)["|\']).*?>/i';
			preg_match_all($pattern, $htmlstring, $matches);			
			//echo '<pre>';print_r ($matches);die;

			$arr_required = explode(",", str_replace(" ","",$paramsvalues->val_required));
			$arr_validate_number = explode(",", str_replace(" ","",$paramsvalues->val_validate_number));
			$arr_validate_digits = explode(",", str_replace(" ","",$paramsvalues->val_validate_digits));
			$arr_validate_alpha = explode(",", str_replace(" ","",$paramsvalues->val_validate_alpha));
			$arr_validate_alphanum = explode(",", str_replace(" ","",$paramsvalues->val_validate_alphanum));
			$arr_validate_date = explode(",", str_replace(" ","",$paramsvalues->val_validate_date));
			$arr_validate_email = explode(",", str_replace(" ","",$paramsvalues->val_validate_email));
			$arr_validate_url = explode(",", str_replace(" ","",$paramsvalues->val_validate_url));
			$arr_validate_date_au = explode(",", str_replace(" ","",$paramsvalues->val_validate_date_au));
			$arr_validate_currency_dollar = explode(",", str_replace(" ","",$paramsvalues->val_validate_currency_dollar));
			$arr_validate_selection = explode(",", str_replace(" ","",$paramsvalues->val_validate_selection));
			$arr_validate_one_required = explode(",", str_replace(" ","",$paramsvalues->val_validate_one_required));
			
			$arr_all = array_merge($arr_required, $arr_validate_number, $arr_validate_digits, $arr_validate_alpha, $arr_validate_alphanum, $arr_validate_date, $arr_validate_email, $arr_validate_url, $arr_validate_date_au, 
			$arr_validate_currency_dollar, $arr_validate_selection, $arr_validate_one_required);
			$i = 0;
			foreach ($matches[0] as $match)
			{
				$full_name = $matches[1][$i]; // with quotes and attribute 'name', for example: name="asdasd"
				$name = $matches[2][$i]; // name value  only
				$i++;
				preg_match('/'.$name.'.*? class=["|\'](.*?)["|\']/i', $match, $class_matches);
				$class_array = array();
			    //echo '<pre>';print_r ($class_matches);die;
				if ($class_matches[0]!=''){
					$class_array[] = $class_matches[1];
				}
				else {
					//nothing
				}

				if(in_array($name,$arr_all)){
					if(in_array($name,$arr_required)){
						$class_array[] = "required";
					}
					if(in_array($name,$arr_validate_number)){
						$class_array[] = "validate-number";
					}
					if(in_array($name,$arr_validate_digits)){
						$class_array[] = "validate-digits";
					}
					if(in_array($name,$arr_validate_alpha)){
						$class_array[] = "validate-alpha";
					}
					if(in_array($name,$arr_validate_alphanum)){
						$class_array[] = "validate-alphanum";
					}
					if(in_array($name,$arr_validate_date)){
						$class_array[] = "validate-date";
					}
					if(in_array($name,$arr_validate_email)){
						$class_array[] = "validate-email";
					}
					if(in_array($name,$arr_validate_url)){
						$class_array[] = "validate-url";
					}
					if(in_array($name,$arr_validate_date_au)){
						$class_array[] = "validate-date-au";
					}
					if(in_array($name,$arr_validate_currency_dollar)){
						$class_array[] = "validate-currency-dollar";
					}
					if(in_array($name,$arr_validate_selection)){
						$class_array[] = "validate-selection";
					}
					if(in_array($name,$arr_validate_one_required)){
						$class_array[] = "validate-one-required";
					}
					
					$class_string = implode(" ",$class_array);
					if ($class_matches[0]!='') {
						$htmlstring = preg_replace('/(name=["|\']'.$name.'["|\'].*?)(class=["|\'].*?["|\'])/i','$1class="'.$class_string.'"', $htmlstring);
					}
					else {
						$htmlstring = str_replace($full_name,$full_name.' class="'.$class_string.'"',$htmlstring);						
					}
				}
			}
		$rows[0]->html = $htmlstring;
		}
	/// end validation //


I have a form with 139 (!!!) controls, where i specify visual classes, and all works perfectly (Note: class-attribute must be added after name-attribute)!!!
Please reply me if you will use this code with next version, otherwise i will have to inject this code everytime when new version is released.
Hope this code will useful.
P.S. and again sorry for my bad english ^_^
GreyHead 21 Apr, 2008
Hi cuhuak,

Thanks for this. I'm sure that Max will look at it.

I doubt that is could be used as it is because there is no way of being sure that the class attribute comes after the name attribute.

It's simpler not to use class attributes in the input fields.

Bob
cuhuak 21 Apr, 2008
Do you realy think that it's simpler to wrap the input fields to specify visual styles than to set the class attrubute at the specific place??
Ok, I'll try to hack it, and it will work though where class attribute was written.
GreyHead 21 Apr, 2008
Hi cuhuak,

If you or I were coding the form then 'No' it's not. But many users just copy and paste forms from anywhere and there is no way of knowing what sequence, if any, the attributes have.

Bob
This topic is locked and no more replies can be posted.