PHP Barcelona Conference 2010

2 views
Skip to first unread message

Àlex Corretgé

unread,
Sep 28, 2010, 3:25:45 AM9/28/10
to ccc...@googlegroups.com
Algú hi anirà?



Atentament / Kind Regards

Àlex Corretgé
a/e - wave: al...@corretge.cat


Carrer de la Font, 2
17142 - Verges
Tel: +34 972 780 422
Cell: +34 669 86 92 64

Serveis Informàtics Corretgé.com SLU

EA3ERT

unread,
Sep 28, 2010, 3:34:25 PM9/28/10
to ccc...@googlegroups.com
Hola llista,

Estic fent un formulari amb una pila de variables. Voldria passar-les
com a variables de sessi�. El problema �s com convertir una variable
d'una entrada de formulari en una variable de sessi�. He provat el codi
de sota per� no funciona. Alguna idea?

Gr�cies pel vostre temps.

Toni Millet

session_start();

$string='
<html>
<body>

<FORM action="prova_alta.php" method="POST">
<INPUT type="text" name="var1"">
<INPUT type="submit" name="enter">
</FORM>
<br>
<br>';

$_SESSION["variable1"]=$var1;

echo $string;

echo('session :'.$_SESSION["variable1"]);

echo ('</body></html>');


Jordi Sabaté

unread,
Sep 28, 2010, 6:06:06 PM9/28/10
to ccc...@googlegroups.com
No se si ho entès bé però diria que t'està complicant una mica no?

Jo faira:

form.php
-------------------------------------------------------------------------------------------------------------
    <form method="post" action="submit.php">
        <input name="var1" value="<?php echo $_SESSION['var1']; ?>">
    </form>
-------------------------------------------------------------------------------------------------------------
un cop fem submit:

submit.php
-------------------------------------------------------------------------------------------------------------
<?php
    if(count($_POST)) {
        foreach($_POST as $k => $v){ $_SESSION[$k] = $v; } //passem les variables de l'array POST al SESSION
    }
?>
-------------------------------------------------------------------------------------------------------------

D'aquesta manera tots els camps que hi ha al formulari quedaran guardats a $_SESSION un cop enviades a submit.php

Si a continuació vols anar a una altra pàgina on ja tindries les variables a $_SESSION 
podries posar després del "if(count($_POST)){ ... }" algo així:
header('Location: seguent.php');

D'aquesta manera tindries tots els camps del formualri de form.php dins $_SESSION de "seguent.php"

Espero haver-te entès! :p 
Salut!

El 28 de setembre de 2010 21:34, EA3ERT <ea3...@qrp.cat> ha escrit:
Hola llista,

Estic fent un formulari amb una pila de variables. Voldria passar-les com a variables de sessió. El problema és com convertir una variable d'una entrada de formulari en una variable de sessió. He provat el codi de sota però no funciona. Alguna idea?

Gràcies pel vostre temps.


Toni Millet

session_start();

$string='
<html>
<body>

<FORM action="prova_alta.php" method="POST">
       <INPUT type="text" name="var1"">
       <INPUT type="submit" name="enter">
</FORM>
<br>
<br>';

$_SESSION["variable1"]=$var1;

echo $string;

echo('session :'.$_SESSION["variable1"]);

echo ('</body></html>');




--
Rebeu aquest misatge pq esteu subscrits al Grup Google "CCCPHP - Consell PHP dels Països Catalans".
Per iniciar un debat, envieu un email a ccc...@googlegroups.com
Per esborrar-se del grup, envieu un email a cccphp-un...@googlegroups.com
Per a més opcions, visiteu aquest grup a http://groups-beta.google.com/group/cccphp?hl=ca



--
__________________________________
 
 Jordi Sabaté
 Cal Serafí
 L'Espluga de Francolí
 Països Catalans
 

moflus

unread,
Sep 30, 2010, 7:23:13 AM9/30/10
to CCCPHP - Consell PHP dels Països Catalans
$_SESSION["variable1"] = $_POST['var1'];

Àlex Corretgé

unread,
Sep 30, 2010, 9:12:02 AM9/30/10
to ccc...@googlegroups.com
També podries fer

if (!empty($_POST))
{
   $_SESSION['POST'] = $_POST;
}

Atentament / Kind Regards

Àlex Corretgé
a/e - wave: al...@corretge.cat


Carrer de la Font, 2
17142 - Verges
Tel: +34 972 780 422
Cell: +34 669 86 92 64

Serveis Informàtics Corretgé.com SLU



El 28 de setembre de 2010 21:34, EA3ERT <ea3...@qrp.cat> ha escrit:
Hola llista,

Estic fent un formulari amb una pila de variables. Voldria passar-les com a variables de sessió. El problema és com convertir una variable d'una entrada de formulari en una variable de sessió. He provat el codi de sota però no funciona. Alguna idea?

Gràcies pel vostre temps.


Toni Millet

session_start();

$string='
<html>
<body>

<FORM action="prova_alta.php" method="POST">
       <INPUT type="text" name="var1"">
       <INPUT type="submit" name="enter">
</FORM>
<br>
<br>';

$_SESSION["variable1"]=$var1;

echo $string;

echo('session :'.$_SESSION["variable1"]);

echo ('</body></html>');

Àlex Corretgé

unread,
Sep 30, 2010, 9:14:56 AM9/30/10
to ccc...@googlegroups.com
ep, que se m'ha escapat el botó d'enviar !!!!


i despres accedeixes per $_SESSION['POST']['var1']

possitiu:
si afegeixes camps al formulari, aquests s'inclouen automàticament a la sessió.

negatiu:
estas guardant dades a la sessió que no han passat per cap validador.

Atentament / Kind Regards

Àlex Corretgé
a/e - wave: al...@corretge.cat


Carrer de la Font, 2
17142 - Verges
Tel: +34 972 780 422
Cell: +34 669 86 92 64

Serveis Informàtics Corretgé.com SLU



Eduard Vidal i Tulsà

unread,
Sep 29, 2010, 4:32:00 AM9/29/10
to ccc...@googlegroups.com
El 28 de setembre de 2010 21:34, EA3ERT <ea3...@qrp.cat> ha escrit:
> Hola llista,
>
> Estic fent un formulari amb una pila de variables. Voldria passar-les com a
> variables de sessió. El problema és com convertir una variable d'una entrada

> de formulari en una variable de sessió. He provat el codi de sota però no
> funciona. Alguna idea?
>
> Gràcies pel vostre temps.

>
> Toni Millet
>
> session_start();
>
> $string='
> <html>
> <body>
>
> <FORM action="prova_alta.php" method="POST">
>        <INPUT type="text" name="var1"">
>        <INPUT type="submit" name="enter">
> </FORM>
> <br>
> <br>';
>
oju, Q les register globals ja no funcionen
> $_SESSION["variable1"]=$_REQUEST['var1'];

>
> echo $string;
>
> echo('session :'.$_SESSION["variable1"]);
>
> echo ('</body></html>');
>
>
>
>
Reply all
Reply to author
Forward
0 new messages