Foros del Web » Programando para Internet » Javascript »

Cambiar Minusculas a mayusculas

Estas en el tema de Cambiar Minusculas a mayusculas en el foro de Javascript en Foros del Web. Hola tengo un problema con un formulario que tiene captcha, cuando escribo en mayusculas todo bien, pero cuando lo escribo el código en minusculas sale ...
  #1 (permalink)  
Antiguo 31/07/2009, 10:59
Avatar de salvador86  
Fecha de Ingreso: enero-2008
Ubicación: Guadalajara- Mexico
Mensajes: 467
Antigüedad: 16 años, 3 meses
Puntos: 2
Cambiar Minusculas a mayusculas

Hola tengo un problema con un formulario que tiene captcha, cuando escribo en mayusculas todo bien, pero cuando lo escribo el código en minusculas sale error, he probado con css que lo que ingresa en la caja de texto que verifica el captcha se muestre en mayusculas pero no me funciono, he encontrado una solución en el foro pero http://www.forosdelweb.com/wiki/PHP:...C3%BAsculas%3F no he logrado ubicar donde poner ese código, pues no soy muy bueno en php.

Les pido una ayuda como puedo usar esta solucion este es el formulario http://www.peru-expeditions.com/c-prueba.php y para su funcionamiento estos archivos:
Código PHP:
<?
        $email_recipient     
'[email protected];[email protected]';

        
session_start();
        
error_reporting(0);
        include(
"class/captchaZDR.php");

        
$capt = new captchaZDR;
        
$wrong_captcha     '';

        if(isset(
$_REQUEST['Submit']) and $capt->check_result()){        
              
$message_send "Mensaje desde la página\n\n      
              Nombre: "
.$_REQUEST['Nombre']." \n
              E-mail: "
.$_REQUEST['Correo']." \n
                Comentario: "
.$_REQUEST['Comentarios']." \n    
                Info: "
.$_REQUEST['Pagina']." \n";

                
$headers .= 'To: <'.$email_recipient.'>' "\r\n";
                
$headers .= 'From: '.$_REQUEST['Nombre'].' <'.$_REQUEST['Correo'].'>' "\r\n";

            if(
mail($email_recipient'SOLICITUD DE INFORMACION PERU EXPEDITIONS' $message_send$headers))
                        
header ("Location: http://www.peru-expeditions.com/c-gracias.html");
                else 
                        echo 
'<div style="color: red"><strong>Hubo un problema en el mensaje. Por favor, inténtelo de nuevo. Gracias.</strong></div>';  
        } 
        
        else{if(isset(
$_REQUEST['Submit']) and (!$capt->check_result()) ) 
                echo 
'<div style="color: red"><b>Intente de nuevo. Actualizar:</b><a href="#" onclick="write_captcha();"><img src="gifs/refresh.gif" border="0" alt="" /></a></div>';
        }
?>
Código PHP:
var http_request false;
   var 
clicks      0;
   function 
makePOSTRequest(urlparameters) {
      
http_request false;
      if (
window.XMLHttpRequest) { // Mozilla, Safari,...
         
http_request = new XMLHttpRequest();
         if (
http_request.overrideMimeType) {
             
// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            
http_request.overrideMimeType('text/html');
         }
      } else if (
window.ActiveXObject) { // IE
         
try {
            
http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (
e) {
            try {
               
http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (
e) {}
         }
      }
      if (!
http_request) {
         
alert('Cannot create XMLHTTP instance');
         return 
false;
      }
      
      
http_request.onreadystatechange alertContents;
      
http_request.open('POST'urltrue);
      
http_request.setRequestHeader("Content-type""application/x-www-form-urlencoded");
      
http_request.setRequestHeader("Content-length"parameters.length);
      
http_request.setRequestHeader("Connection""close");
      
http_request.send(parameters);
   }

   function 
alertContents() {
      if (
http_request.readyState == 4) {
         if (
http_request.status == 200) {
            
//alert(http_request.responseText);
            
result http_request.responseText;
            
document.getElementById('myspan').innerHTML result;            
         } else {
            
alert('Hubo un problema en la Solicitud.');
         }
      }
   }
   
   function 
get(obj) {
      var 
poststr "Nombre=" encodeURIdocument.getElementById("Nombre").value ) +
                    
"&Correo=" encodeURIdocument.getElementById("Correo").value ) +
              
"&Comentarios=" encodeURIdocument.getElementById("Comentarios").value )+
              
"&capt=" encodeURIdocument.getElementById("capt").value )+              
              
"&Submit=" encodeURIdocument.getElementById("Submit").value )+
                
"&Pagina=" encodeURIdocument.getElementById("Pagina").value );
      
makePOSTRequest('captcha/c-envio-chico.php'poststr);
   }

   function 
write_captcha(){
        
define('Nombre''string''Nombre');
        
define('Correo''email''E-mail');
       
clicks++;
       
document.getElementById('capt').value        ''
      
document.getElementById('captcha_id').innerHTML '<img src="captcha/captcha_img.php?clicks=' clicks '" border="0" alt="" /><a href="#" onclick="write_captcha();"><img src="gifs/refresh.gif" border="0" alt="" /></a>';
   return 
false;
   } 

Última edición por salvador86; 31/07/2009 a las 11:04 Razón: editar
  #2 (permalink)  
Antiguo 31/07/2009, 11:06
Avatar de salvador86  
Fecha de Ingreso: enero-2008
Ubicación: Guadalajara- Mexico
Mensajes: 467
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Cambiar Minusculas a mayusculas

Y este es mi captcha
Código PHP:
<?php
class captchaZDR {

  var 
$UserString;
  var 
$font_path;
  
  function 
captchaZDR(){
      switch(
rand(1,3))
        {
          case 
1  $this->font_path 'png_bank/font.ttf';            break;
          case 
2  $this->font_path 'png_bank/freemonobold.ttf';    break;
          case 
3  $this->font_path 'png_bank/freesans.ttf';        break;
          
          default : 
$this->font_path 'png_bank/font.ttf';             break;      
        }  
  }

  function 
LoadPNG(){  
       
$bgNUM rand(1,8);
       
$im = @imagecreatefrompng('png_bank/bg'.$bgNUM.'.png'); /* Attempt to open */
       
if (!$im) { 
           
$im  imagecreatetruecolor(15030); /* Create a blank image */
           
$bgc imagecolorallocate($im255255255);
           
$tc  imagecolorallocate($im000);
           
imagefilledrectangle($im0015030$bgc);
           
imagestring($im155"Error loading $imgname"$tc);
       }
       return 
$im;
  }
    
  function 
drawElipse($image){
        for(
$i=0;$i<5;$i++){
            
// choose a color for the ellipse
            
$red         rand(0,155);
            
$green       rand(0,155);
            
$blue        rand(0,155);
            
$col_ellipse imagecolorallocate($image$red$green$blue);
            
// draw the ellipse
            
$cx rand(50,250);
            
$cy rand(50,250);
            
$cw rand(30,250);
            
$ch rand(20,250);
            
imageellipse($image$cx$cy$cw$ch$col_ellipse);
        }
        
        foreach (
range('A''Z') as $letter) {
            
$red    rand(0,155);
            
$green  rand(0,155);
            
$blue   rand(0,155);
            
$col_ellipse  imagecolorallocate($image$red$green$blue);  
            
$font_size    3//rand(1,12);
            
$x      rand(0,200);
            
$y      rand(0,100);
            
imagechar($image$font_size$x$y$letter$col_ellipse);       
        } 

        foreach (
range('0''9') as $letter) {
            
$red    rand(0,155);
            
$green  rand(0,155);
            
$blue   rand(0,155);
            
$col_ellipse  imagecolorallocate($image$red$green$blue);  
            
$font_size    1
            
$x      rand(0,200);
            
$y      rand(0,100);
            
imagechar($image$font_size$x$y$letter$col_ellipse);                 
        }         
       
  }
  
  function 
task_string(){
  
         
// create a image from png bank
        
$image $this->LoadPNG(); 
  
        
$string_a = array("A","B","C","D","E","F","G","H","J","K",
                          
"L","M","N","P","R","S","T","U","V","W","X","Y","Z",
                          
"2","3","4","5","6","7","8","9");
  
        
$width 0;  
        for(
$i=0;$i<5;$i++)
        {
            
$colour     imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
            
$font        $this->font_path;
            
$angle      rand(-15,15);
            
// Add the text
            
$width_pos  rand(10,30);
            
$width      $width  $width_pos;
            
$height     rand(30,30);
            
$temp       $string_a[rand(0,25)];
            
$this->UserString .= $temp;
            
imagettftext($image26$angle$width$height$colour$font$temp);
            
$width    $width 3;
            
$height   $height 3;
            
imagettftext($image26$angle$width$height$colour$font$temp);

        }
        
        
$_SESSION['captcha'] = $this->UserString;
        
        return 
$image;
  }
  
  function 
task_sum(){
         
// create a image from png bank
          
$image    $this->LoadPNG(); 
        
          
$colour imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$font   $this->font_path;
          
$angle  rand(-15,15);
          
// Add the text
          
$width rand(20,30);
          
$height rand(35,30);
          
          
$number1 rand(1,99);
          
$number2 rand(1,9);
  
          
imagettftext($image26$angle$width$height$colour$font$number1);
          
          
$colour imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$width  += 45
          
imagettftext($image260$width$height$colour$font'+');
  
          
$colour   imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$width   += 25
          
$angle    rand(-15,15);
          
imagettftext($image26$angle$width$height$colour$font$number2.'=?');
  
          
$this->UserString $number1+$number2;  
          
          
$_SESSION['captcha'] = $this->UserString;
  
          return 
$image;         
  }

  function 
task_deduction(){
         
// create a image from png bank
          
$image    $this->LoadPNG(); 
        
          
$colour imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$font   $this->font_path;
          
$angle  rand(-15,15);
          
// Add the text
          
$width rand(20,30);
          
$height rand(35,30);
          
          
$number1 rand(1,99);
          
$number2 rand(1,9);
  
          
imagettftext($image26$angle$width$height$colour$font$number1);
          
          
$colour imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$width  += 45
          
imagettftext($image260$width$height$colour$font'-');
  
          
$colour   imagecolorallocate($imagerand(0,155), rand(0,155), rand(0,155));
          
$width   += 25
          
$angle    rand(-15,15);
          
imagettftext($image26$angle$width$height$colour$font$number2.'=?');
  
          
$this->UserString $number1-$number2;  
          
          
$_SESSION['captcha'] = $this->UserString;
  
          return 
$image;         
  } 
 
  function 
display(){
       
        switch(
rand(1,3))
        {
          case 
1  $image  $this->task_string();  break;
          case 
2  $image  $this->task_string();  break;
          case 
3  $image  $this->task_string();  break;
          
          default : 
$image  $this->task_string();     break;      
        }
        
        
$this->drawElipse($image);
        
        
// output the picture
        
header("Content-type: image/png");
        
imagepng($image);  
  } 

  function 
check_result(){
    if(!isset(
$_SESSION['captcha']) || $_SESSION['captcha']!=$_REQUEST['capt'] || $_SESSION['captcha']=='BADCODE')
    {        
        
$_SESSION['captcha']='BADCODE';
        return 
false;
    } 
    else 
    {
          return 
true;
    }
  } 

}

?>
Muchas Gracias les pido una ayuda

Última edición por salvador86; 31/07/2009 a las 11:08 Razón: editar
  #3 (permalink)  
Antiguo 31/07/2009, 11:17
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Cambiar Minusculas a mayusculas

Hay varias formas de lograr que las minusculas se conviertan en mayuscula por ejemplo con javascript lo puedes hacer mientras va escribiendo sea obligado mayuscula. Bueno pero para convertir una valor de minuscula a mayuscula con PHP lo puedes hacer con la funcion predefinida de php strtoupper(). Esta es la forma de hacerlo

Código PHP:
Ver original
  1. $str = strtoupper($_POST["campo"]);
  2. echo $str;
  #4 (permalink)  
Antiguo 31/07/2009, 11:19
 
Fecha de Ingreso: julio-2009
Mensajes: 72
Antigüedad: 14 años, 8 meses
Puntos: 16
Respuesta: Cambiar Minusculas a mayusculas

No se si va a funcionar pero trata de cambiar esta funcion de esta forma...

Código PHP:
function check_result(){
    if(!isset(
$_SESSION['captcha']) || strtoupper($_SESSION['captcha']) != strtoupper($_REQUEST['capt']) || $_SESSION['captcha']=='BADCODE')
    {        
        
$_SESSION['captcha']='BADCODE';
        return 
false;
    } 
    else 
    {
          return 
true;
    }
  } 
  #5 (permalink)  
Antiguo 31/07/2009, 11:19
 
Fecha de Ingreso: enero-2009
Mensajes: 408
Antigüedad: 15 años, 3 meses
Puntos: 14
Respuesta: Cambiar Minusculas a mayusculas

Hola , puedes usar la función strtoupper('cadena'); .

Ejemplo

Código php:
Ver original
  1. <?php
  2. $cadena='micasa';
  3. echo strtoupper($cadena); // y saldra MICASA
  4. ?>

Saludos
  #6 (permalink)  
Antiguo 31/07/2009, 13:07
Avatar de salvador86  
Fecha de Ingreso: enero-2008
Ubicación: Guadalajara- Mexico
Mensajes: 467
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Cambiar Minusculas a mayusculas

Muchas Gracias Pochos, con este cambio si salio muy bien gracias, me salvaste de un despido jejejeje, Gracias y a todos los que respondieron
  #7 (permalink)  
Antiguo 01/08/2009, 09:26
Avatar de salvador86  
Fecha de Ingreso: enero-2008
Ubicación: Guadalajara- Mexico
Mensajes: 467
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Cambiar Minusculas a mayusculas

En mi mensaje me llegan simbolos extraños cuando se ingresan ñ y tildes se puede remediar tambien, gracias
  #8 (permalink)  
Antiguo 01/08/2009, 09:34
 
Fecha de Ingreso: enero-2009
Mensajes: 408
Antigüedad: 15 años, 3 meses
Puntos: 14
Respuesta: Cambiar Minusculas a mayusculas

es problema de la codificación de tu codigo , esos simbolos extraños se debe a que tu seguro envias los datos en iso y tu sistema trabaje en UTF .

Te dejo unos links para que te fijes hay ejemplos incluso de como manejar datos utf e iso y como convertirlos de uno a otro.

http://ar.php.net/manual/en/function.utf8-decode.php

http://ar.php.net/manual/en/function.utf8-encode.php

Saludos!
  #9 (permalink)  
Antiguo 01/08/2009, 13:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Cambiar Minusculas a mayusculas

Tema trasladado desde PHP
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:13.