Forums

LiveValidation problem

sebslater 12 Nov, 2009
I'm having real difficulty with liveValidation - I tried to follow some of the previous posts on this topic but they didn't work. Sorry - I am pretty new to this...

here is part of my form code - I have tried modifying this and the js snippet box with no job...


    <div class="form_item">
      <div class="form_element cf_textbox">
        <label class="cf_label" style="width: 150px;">Mobile Phone</label>
        <input class="cf_inputbox required validate-digits" maxlength="11" size="30" title="Please enter a UK mobile number without any spaces." id="text_9" name="cr_username" type="text" />
      <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
                <div class="tooltipdiv">Mobile Phone :: We will send a validation code shortly.</div>
      </div>
    </div>


I want to validate this field with the regex ^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$

page is http://www.go-text.com/index.php?option ... Itemid=220

thanks,


Seb
GreyHead 12 Nov, 2009
Hi Seb,

Thanks for posting here, let' sme post a general solution for regexp validation. This brings together several code snippets that have been posted in different threads here.

The code goes into the Form HTML box:
<?php
$script = "
var field_name_val = new LiveValidation('field_name', {
  validMessage: 'Passed!'
});
field_name_val.add(Validate.Format( 'live validation', { 
  pattern: /^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$/i, 
  failureMessage: "Failed!" 
});
";

jimport('joomla.environment.browser');
$browser = JBrowser::getInstance();
if ( $browser->getBrowser() == 'msie' ) {
  $loader = 'load';
} else {
  $loader = 'domready';
} 
$doc =& JFactory::getDocument();
$script = "window.addEvent('$loader', function() { $script });";
$doc->addScriptDeclaration($script);
?>
You need to replace field_name (three times) with the id of the field that you are testing. You can also change the success and failure messages.

The core of this code are the Validate.Format lines. I've pasted your regexp in there but any other valid regexp should work as well.

Most of the remaining code loads the script snippet into the page header using slightly different code versions for IE & 'other browsers'.

Bob

PS Not tested and may need debugging!
sebslater 12 Nov, 2009
I'm getting this error now.

Parse error: syntax error, unexpected T_STRING in ***/components/com_chronocontact/chronocontact.html.php(180) : eval()'d code on line 29

I've restored form to how it was.
GreyHead 12 Nov, 2009
Hi Seb,

Sorry, I think that's bad quotes. Plese change this line
  failureMessage: 'Failed!' 

Bob
sebslater 12 Nov, 2009
validation still not working - im sure im being stupid but im trying to pick this up;

This is now my code for that field and it just passes the validation. I've removed the input class from before - was I correct to do this?


<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Mobile Phone</label>
    <input maxlength="11" size="30" title="Please enter a UK mobile number without any spaces." id="text_9" name="cr_username" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Mobile Phone :: We will send a validation code shortly.</div>
  </div>
</div>
<?php
$script = "
var text_9_val = new LiveValidation('text_9', {
  validMessage: 'Passed!'
});
text_9_val.add(Validate.Format( 'live validation', {
  pattern: /^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$/i,
  failureMessage: 'Failed!'
});
";

jimport('joomla.environment.browser');
$browser = JBrowser::getInstance();
if ( $browser->getBrowser() == 'msie' ) {
  $loader = 'load';
} else {
  $loader = 'domready';
}
$doc =& JFactory::getDocument();
$script = "window.addEvent('$loader', function() { $script });";
$doc->addScriptDeclaration($script);
?>



Thanks a lot.
GreyHead 12 Nov, 2009
Hi Seb,

One more - it's proving to be a 'more haste, less speed' day:
<?php
$script = "
var text_9_val = new LiveValidation('text_9', {
  validMessage: 'Passed!'
});
text_9_val.add(
  Validate.Format, {
    pattern: /^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$/i,
    failureMessage: 'Failed!'
});
";

jimport('joomla.environment.browser');
$browser = JBrowser::getInstance();
if ( $browser->getBrowser() == 'msie' ) {
  $loader = 'load';
} else {
  $loader = 'domready';
}
$doc =& JFactory::getDocument();
$script = "window.addEvent('$loader', function() { $script });";
$doc->addScriptDeclaration($script);
?>
This one has been tested and works in FireFox.

Bob
sebslater 12 Nov, 2009
Thanks - all now working except

a. the green box doesn't stay around the password box and
b. how do you livevalidate the retype password box to value of the password?

Have tried a few suggestions without luck...

thanks

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