Jols Posted December 3, 2008 Share Posted December 3, 2008 Hi, first off i just want to tell you that this forum is awesome... Secondly I have a little problem I was hoping someone could help me with... I have this PHP form, that i partially wrote myself and partially cot from a freeware patch available on the internet. This form (function) allows a user of a role playing game (such as my own small game) to send messages to a chat room using a selectable Name, Sex and Rank (it's a RPG play by chat 'bout stargate, therefore we need ranks ;-)). It works just fine really, the only little (and that's irony) problem is that whenever a user uses this form, he has to complete all three fields, write and send the message and then, if he wants to use the same "created character" again he has to complete these fields again because they "reset" after pressing "send" (the game is in Italian, therefore the button to send the message is labeled "INVIA"). I would like to program this form somehow to let the fields remain completed even after sending the message. And ideally to reset the form one would have to close the form and open it again. I tried for some time now, but I just can't get it right. I hope someone here can help me out, I'm sorry for my far-from-perfect English, Thanks, Garon J. Here is the code of said form: <? session_start(); include ("inc/parametri.inc.php"); include ("inc/controllo.php"); include ("inc/open2.php"); $sel_stanza = mysql_query("SELECT * FROM Presenti WHERE Nome = '{$_SESSION[Login]}'"); $row_stanza = mysql_fetch_array($sel_stanza); $sel_mostr = mysql_query("SELECT * FROM Gilda"); ?> <html> <style> select { border-right: #FFFFFF 1px solid; border-top: #FFFFFF 1px solid; border-left: #FFFFFF 1px solid; border-bottom: #FFFFFF 1px solid; font-size: 14px; font-weight: bold; font-family: "Times New Roman", Serif; color: #FFFFFF; background-color: #000000; } input{ color: #FFFFFF; background-color:#000000; border-right: #FFFFFF 1px solid; border-top: #FFFFFF 1px solid; border-left: #FFFFFF 1px solid; border-bottom: #FFFFFF 1px solid; } </style> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style> BODY {font-size:10px; text-decoration: none; font-family:verdana; color:white; font-weight:normal;} TD {font-size:10px; text-decoration: none; font-family:verdana; color:white; font-weight:normal;} TABLE {font-size:10px; text-decoration: none; font-family:verdana; color:white; font-weight:normal;} </style> </head> <body BACKGROUND="PNGCreator.jpg" style="text-align:center;" topmargin=0 leftmargin=0 bgcolor=#666666> <? include ("inc/controlloesilio.php"); if (($_SESSION['Master']=='1')||($_SESSION['Super_S'] == 1)||($_SESSION['Admin_S'] == 1)) { if(isset($_POST['Tipo'])){ $Tipo = $_POST['Tipo']; $sesso = $_POST['sesso']; $Stanza = $row_stanza['Stanza']; $Msg = $_POST['Messaggio']; $Msg = stripslashes($Msg); $mittente = $_POST['png']; $Gif = $_POST['Gif']; $Msg = substr($Msg, 0, min(strlen($Msg), 1000)); $Msg = addslashes($Msg); $sesso = trim($sesso); if ($sesso != "") { if ($sesso == "M") { $img_ses = "m"; } if ($sesso == "F") { $img_ses = "f"; } else { $img_ses = "m"; } $des_razz = "PNG"; $Tipo = trim($Tipo); $url = trim($url); } if ($Tipo == "H" ) { $Msg = "<div align=\'center\'><img src=\'".$url."\'></div>"; } $MySql = "INSERT INTO Chat (Stanza, Mittente, Destinatario, Ora, Testo, Sesso, ImgGilda, DescGilda, ImgRazza, DescRazza, Tipo)"; $MySql .= "VALUES ('".addslashes($Stanza)."', '".addslashes($mittente)."', '".addslashes($Dest)."', NOW(), '".$Msg."', '$img_ses', '$Gif', '$CharAdd', '$ImgRazza_S', '$des_razz', '$Tipo')"; mysql_query($MySql) or die(mysql_error()); # mysql_query($MySqlBackup); #BACKUP DELLA CHAT # mysql_query($MySqlBackup2); #CANCELLA I MESSAGGI PIU VECCHI DI 20 MINUTI } ?> <br><br><br>Testo del PNG: <form method="post" action="pngmaster.php" name=invio > <select name=sesso> <option>M </option> <option>F </option> </select> <input type="text" name=png size=10 value="Soldato" ><select name="Gif"> <?php while($row_mostr = mysql_fetch_array($sel_mostr)){ echo "<option value=\"gala/$row_mostr[urlImg]\">$row_mostr[Gilda]</option>"; } ?> </select> <input type="text" name=Messaggio size=60><input type="submit" value="Invia" style="font-weight:bold;font-family:Verdana;font-size:8pt"><input type="hidden" name="Tipo" value="P"> </form> Azioni del Png:<br> <form method="post" action="pngmaster.php" name=invioaz > <input type="text" name=png size=10 value="Soldato" ><input type="text" name=Messaggio size=60><input type="submit" value="Invia" style="font-weight:bold;font-family:Verdana;font-size:8pt"><input type="hidden" name="Tipo" value="A"> </form> <br><br> <? } else { ?> Utente non autorizzato <? } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135303-problems-with-php-form/ Share on other sites More sharing options...
gaza165 Posted December 3, 2008 Share Posted December 3, 2008 In order to keep the fields in the text boxes you will need to store the post data in sessions, so when the page is posted it is redirected back to the form. The value of the input will be the value that was posted orginally... Quote Link to comment https://forums.phpfreaks.com/topic/135303-problems-with-php-form/#findComment-704776 Share on other sites More sharing options...
Jols Posted December 3, 2008 Author Share Posted December 3, 2008 In order to keep the fields in the text boxes you will need to store the post data in sessions, so when the page is posted it is redirected back to the form. The value of the input will be the value that was posted orginally... I think I understand what you mean, but I'm a bit lost as to the how I would do that...Would I hve to "store" said values in a database table ? Quote Link to comment https://forums.phpfreaks.com/topic/135303-problems-with-php-form/#findComment-705050 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 In order to keep the fields in the text boxes you will need to store the post data in sessions, so when the page is posted it is redirected back to the form. The value of the input will be the value that was posted orginally... I think I understand what you mean, but I'm a bit lost as to the how I would do that...Would I hve to "store" said values in a database table ? No just session: <?php session_start(); if (isset($_POST) && is_array($_POST)) { foreach ($_POST as $key => $val) $_SESSION[$key] = $val; } ?> Then just add this where you want the value displayed: <?php $name = (isset($_SESSION['name']) ? $_SESSION['name'] : ''); echo '<input type="text" name="name" value="' . $name . '" />'; ?> That should get you rolling. Just remember to unset the session data when done or else the next page load it will display the old data. Quote Link to comment https://forums.phpfreaks.com/topic/135303-problems-with-php-form/#findComment-705060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.