austin350s10 Posted May 29, 2009 Share Posted May 29, 2009 How do you make a reset button on an HTML form work when you are using a session to store the values in the form? Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/ Share on other sites More sharing options...
ngreenwood6 Posted May 29, 2009 Share Posted May 29, 2009 Make it so that when you hit the reset button it clears the session variables. Not sure I understand unless that explains it. Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845063 Share on other sites More sharing options...
austin350s10 Posted May 29, 2009 Author Share Posted May 29, 2009 Below is an example of the code an am using. I am just trying to make the reset button clear the values in the session but I don't really know how to do that. <?php session_start(); if (isset($_SESSION['Fname'])){ $Fname_value = "value=\"".$_SESSION['Fname']."\" "; } else{ $Fname_value = ""; } ?> <form> First Name:<input type="text" name="Fname" id="Fname" tabindex="1" title="first name" <?php print $Fname_value; ?>/> <input id="submit" type="submit" value="Submit"/> <input type="reset" name="Reset" value="Reset" /> Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845068 Share on other sites More sharing options...
mikesta707 Posted May 29, 2009 Share Posted May 29, 2009 I don't think you will be able to reset the session variable, without refreshing the page since PHP is parsed server side. All the reset button does is clear the value of the HTML form I'm not really sure how to accomplish what you want to accomplish. Sorry, hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845072 Share on other sites More sharing options...
ngreenwood6 Posted May 29, 2009 Share Posted May 29, 2009 I think you are looking for something like this: <?php session_start(); if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit") { $_SESSION['first_name'] = $_POST['first_name']; } else { $_SESSION['first_name'] = ""; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> First Name: <input type="text" name="first_name" value="<?php echo $_SESSION['first_name']; ?>" /> <input type="submit" name="Submit" value="Submit"/> <input type="submit" name="Submit" value="Reset" /> <br> <?php echo 'The name entered was : '.$_SESSION['first_name']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845077 Share on other sites More sharing options...
austin350s10 Posted May 29, 2009 Author Share Posted May 29, 2009 Oh thats fine. All I am looking for is a button that will clear the the form but being that everything is stored in a session when a user clicks the reset button nothing happens. I thought something like this: <input type="reset" name="Reset" id="button" value="Reset" <?php session_destroy();?>/> would work but no luck.... Any ideas? Thanks, -Austin- Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845078 Share on other sites More sharing options...
Hybride Posted May 29, 2009 Share Posted May 29, 2009 <?php if(isset($_POST['Reset'])) { session_destroy(); } ?> Is that what you mean? If you press the Reset button, then only the session is destroyed. Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845083 Share on other sites More sharing options...
ngreenwood6 Posted May 29, 2009 Share Posted May 29, 2009 All you would have to do is change the else clause in the code that I gave you to session_destroy() Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845084 Share on other sites More sharing options...
austin350s10 Posted May 29, 2009 Author Share Posted May 29, 2009 n/m I was so close...but this does the trick. <input type="reset" name="Reset" id="button" value="Reset" <?php session_destroy(); ?> onClick="window.location.reload()"/> I had it right but the page needs to be refreshed to clear the values... Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845098 Share on other sites More sharing options...
ngreenwood6 Posted May 29, 2009 Share Posted May 29, 2009 I just hope you are not using your original code because it is not the way a form should be used. look at my code and you can see the difference. Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845103 Share on other sites More sharing options...
austin350s10 Posted May 29, 2009 Author Share Posted May 29, 2009 I know...but its kinda goofy because of the way everything is laid out. The code I had as an example was just an example. I am using reCAPTCHA and a separate mail handler program. My actually code looks like this: <?php session_start(); if (isset($_SESSION['Fname'])){ $Fname_value = "value=\"".$_SESSION['Fname']."\" "; } else{ $Fname_value = ""; } session_start(); if (isset($_SESSION['Lname'])){ $Lname_value = "value=\"".$_SESSION['Lname']."\" "; } else{ $Lname_value = ""; } session_start(); if (isset($_SESSION['email'])){ $email_value = "value=\"".$_SESSION['email']."\" "; } else{ $email_value = ""; } session_start(); if (isset($_SESSION['occ'])){ $occ_value = "value=\"".$_SESSION['occ']."\" "; } else{ $occ_value = ""; } session_start(); if (isset($_SESSION['referral'])){ $referral_value = "value=\"".$_SESSION['referral']."\" "; } else{ $referral_value = ""; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Request Our Newsletter</title> <link rel="shortcut icon" type="image/x-icon" href="../assets/images/icon.ico" > <link href="../css/layout/twoColFixLtHdr.css" rel="stylesheet" type="text/css" /> <!--[if IE 5]> <style type="text/css"> /* place css box model fixes for IE 5* in this conditional comment */ .twoColFixLtHdr #sidebar1 { width: 230px; } </style> <![endif]--><!--[if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColFixLtHdr #sidebar1 { padding-top: 1px; } .twoColFixLtHdr #mainContent { zoom: 1;} /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> <script src="../assets/flash/AC_RunActiveContent.js" type="text/javascript"></script> <script src="../SpryAssets/Forms/SpryValidationTextField.js" type="text/javascript"></script> <script src="../SpryAssets/Forms/SpryValidationSelect.js" type="text/javascript"></script> <link href="../css/text/text.css" rel="stylesheet" type="text/css" /> <link href="../css/layout/Forms/forms.css" rel="stylesheet" type="text/css" /> <link href="../SpryAssets/Forms/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <link href="../SpryAssets/Forms/SpryValidationSelect.css" rel="stylesheet" type="text/css" /> </head> <body class="twoColFixLtHdr"> <div id="container"> <div id="header"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','name','banner','width','980','height','190','id','banner','title','navigation_bar','src','../assets/flash/banner','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../assets/flash/banner' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" name="banner" width="980" height="190" id="banner" title="navigation_bar"> <param name="movie" value="../assets/flash/banner.swf" /> <param name="quality" value="high" /> <embed src="../assets/flash/banner.swf" width="980" height="190" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" name="banner"></embed> </object> </noscript> <noscript> <a href="../index.html">Home</a> | <a href="../About-Us.html">About Us</a> | <a href="../Benefits.html">Benefits</a> | <a href="../Products.html">Products</a> | <a href="../News.html">News</a> | <a href="../ContactUs.html">Contact Us</a> | <a href="../Employment.html">Employment</a> </noscript> <!-- end #header --></div> <div id="sidebar1"> <!-- end #sidebar1 --> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','150','height','35','title','Log-in','src','../assets/flash/LoginBtn','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../assets/flash/LoginBtn' ); //end AC code </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="35" title="Log-in"> <param name="movie" value="../assets/flash/LoginBtn.swf" /> <param name="quality" value="high" /> <embed src="../assets/flash/LoginBtn.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35"></embed> </object> </noscript> <noscript> <a href="../Employee/EmpIndex.html">Log-in</a> </noscript> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','150','height','35','title','news','src','../assets/flash/NewsBtn','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../assets/flash/NewsBtn' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="35" title="news"> <param name="movie" value="../assets/flash/NewsBtn.swf" /> <param name="quality" value="high" /> <embed src="../assets/flash/NewsBtn.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35"></embed> </object> </noscript> <noscript> <a href="../Latest-News.html">The Latest</a> </noscript> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','150','height','35','title','request service','src','../assets/flash/RequestBtn','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../assets/flash/RequestBtn' ); //end AC code </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="35" title="request service"> <param name="movie" value="../assets/flash/RequestBtn.swf" /> <param name="quality" value="high" /> <embed src="../assets/flash/RequestBtn.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35"></embed> </object> </noscript> <noscript> <a href="../Forms/request-homecare.html">Request Service</a> </noscript> </div> <div id="mainContent"> <form action="newletterForm.php" method="post"> <fieldset class="radius"> <legend>Receive Our Newletter</legend> <dl> <dt><label for="Fname">First Name:</label></dt><dd><span id="sprytextfield1"> <input type="text" name="Fname" id="Fname" tabindex="1" title="first name" <?php print $Fname_value; ?>/> <span class="textfieldRequiredMsg">Your first name is required.</span></span></dd> <dt><label for="Lname">Last Name:</label></dt><dd><span id="sprytextfield2"> <input type="text" name="Lname" id="Lname" tabindex="2" title="last name"<?php print $Lname_value; ?>/> <span class="textfieldRequiredMsg">Your last name is required.</span></span></dd> <dt><label for="email">Email:</label></dt><dd><span id="sprytextfield3"> <input type="text" name="email" id="email" tabindex="3" title="email address"<?php print $email_value; ?>/> <span class="textfieldRequiredMsg">A email address is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></dd> <dt><label for="occ">Occupation:</label></dt><dd><span id="sprytextfield4"> <input type="text" name="occ" id="occ" tabindex="4" title="type on your occupation"<?php print $occ_value; ?>/> <span class="textfieldRequiredMsg">Please let us know your occupation.</span></span> <dt><label for="referral">How did you hear of us?</label> </dt><dd><span id="spryselect1"> <select name="referral" id="dub" title="referral source" tabindex = "5"> <option value="-1">--select one--</option> <option value="google"<?php if($_SESSION['referral'] == google) print "selected"; ?>>google</option> <option value="web_search"<?php if($_SESSION['referral'] == web_search) print "selected"; ?>>web search</option> <option value="email"<?php if($_SESSION['referral'] == email) print "selected"; ?>>email</option> <option value="news_paper"<?php if($_SESSION['referral'] == news_paper) print "selected"; ?>>news paper</option> <option value="radio"<?php if($_SESSION['referral'] == radio) print "selected"; ?>>radio</option> <option value="TV"<?php if($_SESSION['referral'] == TV) print "selected"; ?>>TV</option> <option value="phone_book"<?php if($_SESSION['referral'] == phone_book) print "selected"; ?>>phone book</option> <option value="van"<?php if($_SESSION['referral'] == van) print "selected"; ?>>our van</option> <option value="direct_mail"<?php if($_SESSION['referral'] == direct_mail) print "selected"; ?>>personal mail</option> <option value="senior_directory"<?php if($_SESSION['referral'] == senior_directory) print "selected"; ?>>senior directory</option> <option value="trade_show"<?php if($_SESSION['referral'] == trade_show) print "selected"; ?>>trade show</option> <option value="hospital_directory"<?php if($_SESSION['referral'] == hospital_directory) print "selected"; ?>>hospital directory</option> <option value="nurse"<?php if($_SESSION['referral'] == nurse) print "selected"; ?>>nurse</option> <option value="social_worker"<?php if($_SESSION['referral'] == social_worker) print "selected"; ?>>social worker</option> <option value="case_manager"<?php if($_SESSION['referral'] == case_manager) print "selected"; ?>>case manager</option> <option value="friend"<?php if($_SESSION['referral'] == friend) print "selected"; ?>>friend</option> <option value="family_member"<?php if($_SESSION['referral'] == family_member) print "selected"; ?>>family member</option> <option value="AHC_Client"<?php if($_SESSION['referral'] == AHC_Client) print "selected"; ?>>AHC Client</option> <option value="AHC_employee"<?php if($_SESSION['referral'] == AHC_employee) print "selected"; ?>>AHC employee</option> <option value="none"<?php if($_SESSION['referral'] == none) print "selected"; ?>>none of the above</option> </select> <span class="selectInvalidMsg">Please let us know how you heard of us.</span> <span class="selectRequiredMsg">Please select an item.</span></span></dd><br /> <?php require_once('../functions/recaptchalib.php'); $publickey = "6LdxmgYAAAAAAOGANE26JXcGmAjI95uZ3VzoMcUh"; echo recaptcha_get_html($publickey); ?><br /> <div align="center"> <input id="submit" type="submit" value="Submit"/> <input type="reset" name="Reset" id="button" value="Reset" <?php session_destroy(); ?> onClick="window.location.reload()"/> </div> </fieldset> </form> <!-- end #mainContent --></div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" /> <div id="footer"> <div id="footerstatment"> <div align="center"> <p>Affordable HomeCare Inc. © 2009<br /> This page last updated <!-- #BeginDate format:Am1 -->May 29, 2009<!-- #EndDate --> <br /> Powered By Austin Adair</p> <a href="../index.html">Home</a> | <a href="../Footer/Links/Links-main.html">Links</a> | <a href="../Site-Map.xml">Site Map</a> | <a href="../News/Selecting-HC.html">FAQ</a> | <a href="../Forms/feed-back.html">Comments</a><br /> <br /> </div> </div> <!-- end #footer --> </div> <!-- end #container --></div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-3877516-2"); pageTracker._trackPageview(); var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "email"); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4"); var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {invalidValue:"-1"}); </script> </body> </html> I just tried to shorten things up a bit...lol Thanks for the concern though...I am really new to PHP but I have this page up live and it seems to work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/160167-reset-session/#findComment-845115 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.