Some help. How can I apply this code or function http://php-aplicado.blogspot.com.es/…s-con-php.html to an OnChange ajax event in a sc form I will apreciate if you can help me.
You must create a function php with that code. and then call it in event ajax onchange.
Thank you very much however I will apreciate if you can send me a little example in sc form using this code, because I tried but it didn’t work
Yo can create a external libarries for that, so yo can use it in other forms. or an easy way is create in your form: Programming - PHP Methods - New Method:
create it with name numtoletras. and paste the code of first function: from first line:
$xarray = array(0 => “Cero”,
until the lines:
} // ENDFOR ($xz)
return trim($xcadena);
in this function there is a toolbar click in f(x). and create an attribute named xcifra.
save this function.
Create other function named subfijo paste the code into function: $xx = trim($xx);
$xstrlen = strlen($xx);
if ($xstrlen == 1 || $xstrlen == 2 || $xstrlen == 3)
$xsub = “”;
//
if ($xstrlen == 4 || $xstrlen == 5 || $xstrlen == 6)
$xsub = “MIL”;
//
return $xsub;
Create an attribute: in f(x) named xx
save this function.
now you can call first function from event ajax: {my_field} = numtoletras({my_value});
Thank you very much Alvagar, it works!
Ok… .
Hello Alvagar, I need help with this function: I have a form with a field named “rut” but a I need to validate with this code but I do not know how to do it, would you please give me some help.
<?php function validaRut($rut){ if(strpos($rut,"-")==false){ $RUT[0] = substr($rut, 0, -1); $RUT[1] = substr($rut, -1); }else{ $RUT = explode("-", trim($rut)); } $elRut = str_replace(".", “”, trim($RUT[0])); $factor = 2; for($i = strlen($elRut)-1; $i >= 0; $i–): $factor = $factor > 7 ? 2 : $factor; $suma += $elRut{$i}*$factor++; endfor; $resto = $suma % 11; $dv = 11 - $resto; if($dv == 11){ $dv=0; }else if($dv == 10){ $dv=“k”; }else{ $dv=$dv; } if($dv == trim(strtolower($RUT[1]))){ return true; }else{ return false; } } ?> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=“http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”> <title></title> </head> <body> <form method=“post” action=""> <label for=“rut”>Ingresa tu RUT para validar</label> <input name=“rut” value="" type=“text” /> <input type=“submit” value=“probar” /> </form> <div> <?php if($_POST[‘rut’]){ if(validaRut($_POST[‘rut’])==true){ echo “El rut “.$_POST[‘rut’].” es válido”; }else{ echo “El rut “.$_POST[‘rut’].” no es incorrecto”; } } ?> </div> <p>El código de esta página es:</p> <pre> <?php echo show_source(FILE);?> </pre> </body> </html>