Casilla de verificación sin valor matrices

  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 6:17 am

Ive consiguió 5 casillas de verificación (días de la semana laboral) en una matriz que hay que aparezcan en una página php

Puedo comprobar lunes, martes, miércoles y viernes para la entrada 0, y el martes, miércoles y jueves para la entrada 1, y me da el siguiente resultado:

Código: [ Select ]
[monday] => Array ( [0] => 1 )
[tuesday] => Array ( [0] => 1 [1] => 1 )
[wednesday] => Array ( [0] => 1 [1] => 1 )
[friday] => Array ( [0] => 1 )
[thursday] => Array ( [0] => 1 )
  1. [monday] => Array ( [0] => 1 )
  2. [tuesday] => Array ( [0] => 1 [1] => 1 )
  3. [wednesday] => Array ( [0] => 1 [1] => 1 )
  4. [friday] => Array ( [0] => 1 )
  5. [thursday] => Array ( [0] => 1 )


Esto es porque la matriz no se inicia hasta que el valor comprobado en primer lugar. Cualquier solución?

Edit: ¿la adición de valores ocultos en la parte delantera de la entrada 0 ayuda?
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Julio 10th, 2009, 6:17 am

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 6:21 am

Im no seguro si he entendido lo que están haciendo aquí, ¿tiene usted ningún código que rodean el problema se puede compartir?
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 6:27 am

Lo sentimos, al releerlo, no parece muy claro.

Ive consiguió una tabla dinámica con la elaboración de este javascript (varias veces):
Código: [ Select ]
<input type="checkbox" name="monday[]" value="1"/
<input type="checkbox" name="tuesday[]" value="1"/>
<input type="checkbox" name="wednesday[]" value="1"/>
<input type="checkbox" name="thursday[]" value="1"/>
<input type="checkbox" name="friday[]" value="1"/>
  1. <input type="checkbox" name="monday[]" value="1"/
  2. <input type="checkbox" name="tuesday[]" value="1"/>
  3. <input type="checkbox" name="wednesday[]" value="1"/>
  4. <input type="checkbox" name="thursday[]" value="1"/>
  5. <input type="checkbox" name="friday[]" value="1"/>


Cuando la primera fila no está plenamente comprobado, la fila después de que aparece como se muestra - "elevó".

Por favor, ver a mi siguiente diagrama.
Attachments:
sophisticateddiagram.jpg
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 6:39 am

Ahh, bien veo el problema ahora. Navegadores no pase sin cuadros para el servidor. Yor resultados están golpeado porque no sabe nada de los valores en blanco.

Yo recomendaría la creación de una función javascript que llame a presentar que devuelve verdadero o falso - como validador de funciones. Usted puede hacer algo como esto donde construir una cadena a partir de los valores con un delimitador, que tirar en una entrada oculta, y que pase.

Alternativamente, usted puede también utilizar para asignar los eventos onchange verdadero / falso a escondidas cuando los insumos son checkboxed su (des) control. Sin embargo, creo que la primera solución es un poco más elegante. Si youd como ayuda hasta que la codificación, hágamelo saber.
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 6:52 am

Gracias Awesome,.

¿Qué Ive consiguió hasta ahora:

HTML Código: [ Select ]
<form id="form1" name="form1" method="post" action="settimetable.php" onSubmit="set_hidden_value()">
 
<input name="mondayhidden" type="hidden" value="toset" />
  1. <form id="form1" name="form1" method="post" action="settimetable.php" onSubmit="set_hidden_value()">
  2.  
  3. <input name="mondayhidden" type="hidden" value="toset" />


Javascript & #058;
Código: [ Select ]
function set_hidden_value()
{
alert('Test');
var checkstring = "";
for (var i=0; i < document.form1.monday.length; i++)
{
if (document.form1.monday[i].checked)
     {
     checkstring = checkstring + "1";
     }
    else
    {
    checkstring = checkstring + "0";
    }
}
document.form1.mondayhidden.value = checkstring;
}
  1. function set_hidden_value()
  2. {
  3. alert('Test');
  4. var checkstring = "";
  5. for (var i=0; i < document.form1.monday.length; i++)
  6. {
  7. if (document.form1.monday[i].checked)
  8.      {
  9.      checkstring = checkstring + "1";
  10.      }
  11.     else
  12.     {
  13.     checkstring = checkstring + "0";
  14.     }
  15. }
  16. document.form1.mondayhidden.value = checkstring;
  17. }


Pero mondayhidden sigue siendo "unset", en lugar de "1101", etc ¿Qué estoy haciendo mal?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 7:26 am

Mejorar el código de trabajo para usted...colgar apretado.
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 7:39 am

Muy apreciada. :)

/ / No vinculados - Heres pantalla una imagen con fondo gris (no feo rectángulo blanco)
Attachments:
21230 copy.gif
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 8:56 am

Lo sentimos, quedó atascado en algo en el trabajo,...echar un vistazo a esto:

alex89.php
Código: [ Select ]
 
<html>
    <head>
        <script language="JavaScript">
            function set_hidden_values()
            {              
                var days = new Array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" );
                var cbVals = new Array( document.form1.mon, document.form1.tue, document.form1.wed, document.form1.thu, document.form1.fri );
               
                for(var i=0; i<cbVals.length; i++)
                {
                    var hiddenDay = document.getElementById(days[i]);
                    hiddenDay.value = "";
                    for(var j=0; j<cbVals[i].length; j++)
                    {
                        hiddenDay.value += (cbVals[i][j].checked) ? "1," : "0,";
                    }
                    hiddenDay.value = hiddenDay.value.substring(0, hiddenDay.value.length-1);
                }
               
                return false;
            }
        </script>
    </head>
    <body>
        <form name="form1" action="alex89_post.php" method="post" onSubmit="set_hidden_values();">
            <input type="hidden" id="Monday" name="Monday" value="" />
            <input type="hidden" id="Tuesday" name="Tuesday" value="" />
            <input type="hidden" id="Wednesday" name="Wednesday" value="" />
            <input type="hidden" id="Thursday" name="Thursday" value="" />
            <input type="hidden" id="Friday" name="Friday" value="" />
            <br />
<?php
            for($i=0; $i<3; $i++) {
                echo '<input type="checkbox" name="mon" />Monday
                    <input type="checkbox" name="tue" />Tuesday
                    <input type="checkbox" name="wed" />Wednesday
                    <input type="checkbox" name="thu" />Thursday
                    <input type="checkbox" name="fri" />Friday
                    <br />';
            }
?>
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>
 
  1.  
  2. <html>
  3.     <head>
  4.         <script language="JavaScript">
  5.             function set_hidden_values()
  6.             {              
  7.                 var days = new Array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" );
  8.                 var cbVals = new Array( document.form1.mon, document.form1.tue, document.form1.wed, document.form1.thu, document.form1.fri );
  9.                
  10.                 for(var i=0; i<cbVals.length; i++)
  11.                 {
  12.                     var hiddenDay = document.getElementById(days[i]);
  13.                     hiddenDay.value = "";
  14.                     for(var j=0; j<cbVals[i].length; j++)
  15.                     {
  16.                         hiddenDay.value += (cbVals[i][j].checked) ? "1," : "0,";
  17.                     }
  18.                     hiddenDay.value = hiddenDay.value.substring(0, hiddenDay.value.length-1);
  19.                 }
  20.                
  21.                 return false;
  22.             }
  23.         </script>
  24.     </head>
  25.     <body>
  26.         <form name="form1" action="alex89_post.php" method="post" onSubmit="set_hidden_values();">
  27.             <input type="hidden" id="Monday" name="Monday" value="" />
  28.             <input type="hidden" id="Tuesday" name="Tuesday" value="" />
  29.             <input type="hidden" id="Wednesday" name="Wednesday" value="" />
  30.             <input type="hidden" id="Thursday" name="Thursday" value="" />
  31.             <input type="hidden" id="Friday" name="Friday" value="" />
  32.             <br />
  33. <?php
  34.             for($i=0; $i<3; $i++) {
  35.                 echo '<input type="checkbox" name="mon" />Monday
  36.                     <input type="checkbox" name="tue" />Tuesday
  37.                     <input type="checkbox" name="wed" />Wednesday
  38.                     <input type="checkbox" name="thu" />Thursday
  39.                     <input type="checkbox" name="fri" />Friday
  40.                     <br />';
  41.             }
  42. ?>
  43.             <input type="submit" value="Submit" />
  44.         </form>
  45.     </body>
  46. </html>
  47.  


alex89_post.php
Código: [ Select ]
 
<?php
 
    $weekdays = array (
        "Monday" => null,
        "Tuesday" => null,
        "Wednesday" => null,
        "Thursday" => null,
        "Friday" => null,
    );
   
    foreach($weekdays as $key=>$val)
        if(isset($_REQUEST[$key]))
            $weekdays[$key] = explode(",",$_REQUEST[$key]);
   
    foreach($weekdays as $key=>$val) {
        echo $key.": ";
        foreach($val as $out) {
            echo $out." ";
        }
        echo "<br />";
    }
 
?>
 
  1.  
  2. <?php
  3.  
  4.     $weekdays = array (
  5.         "Monday" => null,
  6.         "Tuesday" => null,
  7.         "Wednesday" => null,
  8.         "Thursday" => null,
  9.         "Friday" => null,
  10.     );
  11.    
  12.     foreach($weekdays as $key=>$val)
  13.         if(isset($_REQUEST[$key]))
  14.             $weekdays[$key] = explode(",",$_REQUEST[$key]);
  15.    
  16.     foreach($weekdays as $key=>$val) {
  17.         echo $key.": ";
  18.         foreach($val as $out) {
  19.             echo $out." ";
  20.         }
  21.         echo "<br />";
  22.     }
  23.  
  24. ?>
  25.  


Demostración en directo aquí .

UPDATE: código editado para incluir a fijar muestra a continuación.
I'd love to change the world, but they won't give me the source code.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 8:57 am

Quote:
No vinculados - Heres pantalla una imagen con fondo gris


Gracias. Ive sido demasiado vago para PS yo mismo, por lo que sólo he dejado. Que no coincidan con el tema oscuro, pero su buen tema para la luz. Avatares no suelen durar demasiado tiempo para mí, anways. :D
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 9:07 am

Youre bastante increíble, ¿lo sabes?

Muchas gracias :)

En acción: http://uwadb.com/timetable/setup.php?id=cal

Edit: Si me voy de vuelta y volver, se añade otra pocas entradas de la final de la clave / matriz.

Presentar, la espalda, presentar =
Lunes: 1 0 01 0 0
Martes: 1 0 01 0 0
Miércoles: 0 1 00 1 0
Jueves: 1 0 01 0 0
Viernes: 1 0 01 0 0

Cualquier forma de limpiarla?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 9:21 am

Su caché de su navegador añadiendo a los campos ocultos. Usted puede modificar la función de dar cuenta de esto si te apetece:

Código: [ Select ]
 
function set_hidden_values()
            {              
                var days = new Array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" );
                var cbVals = new Array( document.form1.mon, document.form1.tue, document.form1.wed, document.form1.thu, document.form1.fri );
               
                for(var i=0; i<cbVals.length; i++)
                {
                    var hiddenDay = document.getElementById(days[i]);
                    hiddenDay.value = "";
                    for(var j=0; j<cbVals[i].length; j++)
                    {
                        hiddenDay.value += (cbVals[i][j].checked) ? "1," : "0,";
                    }
                    hiddenDay.value = hiddenDay.value.substring(0, hiddenDay.value.length-1);
                }
               
                return false;
            }
 
  1.  
  2. function set_hidden_values()
  3.             {              
  4.                 var days = new Array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" );
  5.                 var cbVals = new Array( document.form1.mon, document.form1.tue, document.form1.wed, document.form1.thu, document.form1.fri );
  6.                
  7.                 for(var i=0; i<cbVals.length; i++)
  8.                 {
  9.                     var hiddenDay = document.getElementById(days[i]);
  10.                     hiddenDay.value = "";
  11.                     for(var j=0; j<cbVals[i].length; j++)
  12.                     {
  13.                         hiddenDay.value += (cbVals[i][j].checked) ? "1," : "0,";
  14.                     }
  15.                     hiddenDay.value = hiddenDay.value.substring(0, hiddenDay.value.length-1);
  16.                 }
  17.                
  18.                 return false;
  19.             }
  20.  
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 9:26 am

¡Salud! :)

Además, acaba de ser difícil :D

Ive consiguió todos los demás elementos dispuestos como sigue:

Código: [ Select ]
$unitcode = $_POST["unitcode"];
#all other variables
 
for ($i = 0; $i < count($unitcode); ++$i) {
echo $unitcode[$i];
echo $category[$i];
#other variables
}
  1. $unitcode = $_POST["unitcode"];
  2. #all other variables
  3.  
  4. for ($i = 0; $i < count($unitcode); ++$i) {
  5. echo $unitcode[$i];
  6. echo $category[$i];
  7. #other variables
  8. }


Cualquier forma de reordenar fácilmente a partir de 5 filas de "0 0 1", etc a las filas i de "1 0 1 0 0"?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 9:29 am

¿Puedes aclarar? Appare notly Im que hoy un poco densa. :)
I'd love to change the world, but they won't give me the source code.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Julio 10th, 2009, 9:31 am

¿Quiere decir que en lugar de ver las matrices por días, en lugar youd verlos por la semana (para la consulta de inserción)?

Actualización: Si es así, agregue esto a la parte inferior de la página PHP de transformación:
Código: [ Select ]
 
$weeks = array();
   
    for($i=0; $i<count($weekdays['Monday']); $i++)
        $weeks[$i] = array (
            'Monday' => $weekdays['Monday'][$i],
            'Tuesday' => $weekdays['Tuesday'][$i],
            'Wednesday' => $weekdays['Wednesday'][$i],
            'Thursday' => $weekdays['Thursday'][$i],
            'Friday' => $weekdays['Friday'][$i]
        );
   
    foreach($weeks as $week) {
        foreach($week as $day => $val) {
            echo $day." - ".$val.", ";
        }
        echo "<br />";
    }
 
  1.  
  2. $weeks = array();
  3.    
  4.     for($i=0; $i<count($weekdays['Monday']); $i++)
  5.         $weeks[$i] = array (
  6.             'Monday' => $weekdays['Monday'][$i],
  7.             'Tuesday' => $weekdays['Tuesday'][$i],
  8.             'Wednesday' => $weekdays['Wednesday'][$i],
  9.             'Thursday' => $weekdays['Thursday'][$i],
  10.             'Friday' => $weekdays['Friday'][$i]
  11.         );
  12.    
  13.     foreach($weeks as $week) {
  14.         foreach($week as $day => $val) {
  15.             echo $day." - ".$val.", ";
  16.         }
  17.         echo "<br />";
  18.     }
  19.  


Demo actualizada .
I'd love to change the world, but they won't give me the source code.
  • alex89
  • Bronze Member
  • Bronze Member
  • Avatar de Usuario
  • Registrado: Jul 18, 2008
  • Mensajes: 239
  • Loc: Western Australia
  • Status: Offline

Nota Julio 10th, 2009, 9:33 am

Sí, pero creo que Ive tengo. Malos hacerle saber en 5
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Julio 10th, 2009, 9:33 am

Publicar Información

  • Total de mensajes en este tema: 17 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 178 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC