(note:sorry, this was originally filed incorrectly under pre-installation)

I know I can simply make a blank area for "phone," but I would like to offer something similar to what is now offered by Thierry through his Phone(CCK) module which adds a validating phone component to a CCK content type. Can I use this with webforms somehow, or does someone have a cleaner solution using the most recent version of webforms(10-23 as of writing this).

Thanks

Art

Comments

BooDy’s picture

This is probably a little bit late but it won't hurt to post it :)

I don't know if there's a cleaner way but this is what I've done in a hurry. You can add a javascript validation in a markup component. In my case I needed a text field which will allow numbers only as an input. So I created a markup component with the following content to validate a textfield component on the form:

<script language="javascript" type="text/javascript">
function phone () 
{

//Of course replace the Element id by your textfield's id
document.getElementById("edit-submitted-1164103292").setAttribute('onkeypress', 'return numbersonly(this, event)');
}
function numbersonly(myfield, e, dec)
{
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}
window.onload = phone;

</script>

I hope this would help :)