Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Usar JavaScript en una Plantilla Smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Spanish
View previous topic :: View next topic  
Author Message
piropeator
Smarty Rookie


Joined: 31 Oct 2007
Posts: 26

PostPosted: Thu Apr 24, 2008 12:44 am    Post subject: Usar JavaScript en una Plantilla Smarty Reply with quote

Quiero usar JavaScript en una plantilla Smarty. Cómo se hace eso?
Pues quiero validar un formulario de ingreso de datos y la validacion la hago con JavaSCript.
Pero al poner el código dentro de la plantilla me sale error.
Back to top
View user's profile Send private message
mrtinez
Smarty Rookie


Joined: 31 Jan 2005
Posts: 26
Location: Mexico

PostPosted: Thu Apr 24, 2008 12:54 pm    Post subject: Usar JavaScript en una Plantilla Smarty Reply with quote

Hola piropeator.

Code:

{literal}
<script>
.......  aqui tu javascript .....
</script>
{/literal}


saludos.
Back to top
View user's profile Send private message Visit poster's website
piropeator
Smarty Rookie


Joined: 31 Oct 2007
Posts: 26

PostPosted: Thu Apr 24, 2008 1:46 pm    Post subject: Re: Usar JavaScript en una Plantilla Smarty Reply with quote

mrtinez wrote:
Hola piropeator.

Code:

{literal}
<script>
.......  aqui tu javascript .....
</script>
{/literal}


saludos.


{literal} ?? Así se llama esa función??
Puedes explicarmelo con un ejemplo? Esta es mi plantilla donde voy a ingresar mis productos y quiero validarlos. Dónde y cómo pongo mi JavaScript??


Producto.form.tpl.php

<html>
<body>
<form action="productos.insertar.php" method="post">
..........Id. Categoria: <input type="text" name="idCategoria" value="1"/><br/>
..........Nombre: <input type="text" name="nombre"/><br/>
..........Descripcion: <input type="text" name="descripcion"/><br/>
..........Precio: <input type="text" name="precio"/> (numérico) <br/>
..........Stock: <input type="text" name="stock"/> (numérico) <br/>
<input type="submit" value="Insertar"/>
</form>
</body>
</html>

Saludos y muchas gracias.
Smile
Back to top
View user's profile Send private message
mrtinez
Smarty Rookie


Joined: 31 Jan 2005
Posts: 26
Location: Mexico

PostPosted: Thu Apr 24, 2008 2:51 pm    Post subject: Usar JavaScript en una Plantilla Smarty Reply with quote

ok, este es tu codigo, y como ejemplo le pondremos una accion al botton.


Code:

<html>
<head><title>Titulo de la Pagina</title>
{literal}
<script>
function valida(){

   alert("estoy en la funcion");
   
}
</script>
{/literal}
</head>
<body>
<form action="productos.insertar.php" method="post">
..........Id. Categoria: <input type="text" name="idCategoria" value="1"/><br/>
..........Nombre: <input type="text" name="nombre"/><br/>
..........Descripcion: <input type="text" name="descripcion"/><br/>
..........Precio: <input type="text" name="precio"/> (numérico) <br/>
..........Stock: <input type="text" name="stock"/> (numérico) <br/>
<input type="button" value="Insertar" action="valida();"/>
</form>
</body>
</html>


para mayor informacion checa esto, es del manual
http://www.lacorona.com.mx/mario/smarty/smarty_manual_es/language.function.literal.html

saludos
Back to top
View user's profile Send private message Visit poster's website
rocesvinto
Smarty Rookie


Joined: 16 Apr 2008
Posts: 5
Location: Granada, Spain

PostPosted: Thu May 01, 2008 11:59 am    Post subject: Mira la clase SmartyValidator Reply with quote

Hola piropeator, tal y como te ha dicho mrtinez la etiqueta es {literal}{/literal}, pero te aconsejo que mires la clase SmartyValidator. No te arrepentirás.

saludos Rocesvinto
Back to top
View user's profile Send private message Visit poster's website
piropeator
Smarty Rookie


Joined: 31 Oct 2007
Posts: 26

PostPosted: Mon May 05, 2008 4:42 pm    Post subject: Re: Usar JavaScript en una Plantilla Smarty Reply with quote

Laughing Gracias, ya reconoce el código dentro de la plantilla.

Pero no logro hacer esto: Quiero que el formulario acepte datos si o si, y si no le doy datos que el foco regrese a la ventana de ingreso. Y cuando le de un dato correcto pase los datos a otro archivo en PHP.
Pero se pasa. Aquí un resumen de mi código.

********** form_ingreso.html
<html>
<title>Datos de Usuario</title>
<script>
function valida_envia(){
//valido el nombre
if (document.fvalida.nombre.value.length==0){
alert("Tiene que escribir su nombre")
document.fvalida.nombre.focus()
return 0;
} else {
//el formulario se envia
alert("Dato correcto");
document.fvalida.submit();
}
}
</script>
</head>

<body>
<form name="fvalida" onsubmit="return valida_envia();" method="POST" action="form_muestra.php">
<table width="383" border="0" bgcolor="#FFFFFF">
<tr>
<th scope="row"><div align="right">Nombre :</div></th>
<td><input type="text" name="nombre"/></td>
</tr>
<tr>
<th colspan="2" scope="row">
<input type="submit" value="Aceptar"/> </th>
</tr>
</table>
</form>
</body>
</html>

****** form_muestra.php ************* lo visualizo para probar.
<head>
<title>EJEMPLO</title>
</head>

<body>
El nombre se fue : <?php echo $_POST['nombre'] ?>
</body>
</html>

Dónde está mi error?
Gracias de antemano. Question
Back to top
View user's profile Send private message
Davod
Smarty Rookie


Joined: 29 Sep 2009
Posts: 21

PostPosted: Thu Oct 01, 2009 12:00 am    Post subject: Reply with quote

Solución sencillísima: Usar Paréntesis de llave doble )o Double-braces) '{{}}' en lugar de uno simple como Delimiter '{}'

Quote:
// A continuación de la Configuracion de Smarty:
$smarty->left_delimiter = "{{";
$smarty->right_delimiter = "}}";


Así eliminamos el problema de los Scripts del lado del Cliente a la hora de parsearlos como Etiquetas Smarty.

Pueden usar cualquier juego de caracteres como Delimiters. Esa fue la solución a mi problema también.

http://www.smarty.net/manual/en/variable.left.delimiter.php
http://www.smarty.net/manual/en/variable.right.delimiter.php
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Spanish All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP