dca_steve Posted August 11, 2011 Share Posted August 11, 2011 Hi all - I have an HTML form, and it allows a user to enter data into a bunch of fields, and at the very end they need to enter in a captcha so the data can then be submitted to a database. After submitting the data, the form reloads with blank fields so the user can enter more data, and I have the captcha functionality disappear, which is what I want it to do b/c the user could enter/submit data dozens of times and I don't want them having to enter in a captcha every time. Anyway, my problems occurs once the user tries to submit more data the second time around....the captcha reappears. I'm attempting to hide the captcha via javascript, but I guess I shouldn't do that? Here's my code: <?php session_start(); require('../captcha/captcha.php'); $captcha_passed = 0; $display_captcha = 'display:block'; $ip_address = $_SERVER['REMOTE_ADDR']; $date_submitted = date('n/j/Y g:i:s A'); $report_year = $_SESSION['report_year']; $institution_name = $_SESSION['institution_name']; $institution_code = $_SESSION['institution_code']; $street_address = $_SESSION['street_address']; $city = $_SESSION['city']; $state = $_SESSION['state']; $zip_code = $_SESSION['zip_code']; $branch_address = $_REQUEST['branch_address']; $branch_city = $_REQUEST['branch_city']; $branch_state = $_REQUEST['branch_state']; $branch_zip = $_REQUEST['branch_zip']; if(isset($_POST['Submit'])){ if($_SESSION['captchacode'] == $_POST['captcha']) { include('mysql_connect.php'); //set query $query="insert into branch_locations_dev(ip_address, date_submitted, report_year, institution_code, branch_address, branch_city, branch_state, branch_zip) values('".addslashes($ip_address)."','".addslashes($date_submitted)."','".addslashes($report_year)."','".addslashes($institution_code)."','".addslashes($branch_address)."','".addslashes($branch_city)."','".addslashes($branch_state)."','".addslashes($branch_zip)."')"; $result = mysql_query($query); if($result){ $_POST=array(); } else { die( 'Invalid form submission' ); } $captcha_passed = 1; $display_captcha = 'display:none'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <!-- DO NOT CHANGE THE ABOVE DOCTYPE --> <!-- *********************************** --> <!-- State of California master template --> <!-- Version 1.10 --> <!-- Last Updated January 4, 2007 --> <!-- *********************************** --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" > <head> <!-- **************************************************************** --> <!-- Begin Document Title - Customize to fit your needs --> <title>Annual Report - Bureau for Private Postsecondary Education</title> <!-- End Document Title --> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <!-- Begin Meta Information - Customize to fit your needs --> <meta name="Author" content="State of California" /> <meta name="Description" content="A website for the State of California, Department of Consumer Affairs, Bureau for Private Postsecondary Education" /> <meta name="Keywords" content="students, schools, bppve, bppe, education, vocational, postsecondary, educational programs, school closure" /> <!-- End Meta Information --> <!-- **************************************************************** --> <script type="text/javascript" src="javascript/navigation.js"></script> <script type="text/javascript" src="javascript/department.js"></script> <script type="text/javascript" src="javascript/search_gss.js"></script> <!-- **************************************************************** --> <script type="text/javascript"> <!-- function validateBranches(theform){ if(theform.branch_address.value=="") { alert('Please indicate the Street Address.'); theform.branch_address.focus(); return false; } if(theform.branch_city.value=="") { alert('Please indicate the City.'); theform.branch_city.focus(); return false; } if(theform.branch_state.value=="") { alert('Please indicate the State.'); theform.branch_state.focus(); return false; } if(theform.branch_zip.value=="") { alert('Please indicate the Zip Code.'); theform.branch_zip.focus(); return false; } } function displayCaptcha(){ document.getElementById('captcha_box').style.display = 'none'; } //--> </script> <!-- Begin Style Information --> <style type="text/css"> <!-- /* ***** The master style sheet - DO NOT CHANGE ***** */ @import url("css/bppe.css"); @import url("css/form.css"); .content_onecolumn { float:left; left: 10px; width: 80%; padding: 8px; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; } --> </style> <!-- End Style Information --> <!-- **************************************************************** --> <!-- Begin JavaScript Variable to Set Active Tab --> <!-- Change the "defaultMainList" value to match the name of the --> <!-- page as listed in the navigation include unordered list --> <script type="text/javascript"> <!-- var defaultMainList = "Home"; // --> </script> <!-- End JavaScript Variable to Set Active Tab --> <!-- **************************************************************** --> </head> <body> <?php include("ssi/heading.php"); ?> <div id="main_content_1"> <div id="main_content_2"> <!-- ********** Left column begins ********** --> <div id="left_column"> <!-- **************************************************************** --> <!-- Begin Left Column Content - Put your right column content here --> <!-- Begin Column Top --> <?php include("ssi/lnav.php"); ?> <!-- End Column Bottom --> <!-- End Left Column Content --> <!-- **************************************************************** --> </div> </div> <!-- ********** Left column ends ********** --> <!-- ********** Right column begins ********** --> <div id="right_column"> <div class="column_inner"> <!-- **************************************************************** --> <!-- Begin Right Column Content - Put your right column content here --> <h3>Right Column</h3> <!-- End Right Column Content --> <!-- **************************************************************** --> </div> </div> <!-- ********** Right column ends ********** --> <!-- ********** Middle column begins ********** --> <div id="middle_column"> <div class="column_inner"> <a name="middle_column"></a> <!-- **************************************************************** --> <!-- Begin Amber Alert - Uncomment to turn on --> <!-- <div id="amber_alert_on"> <a href="http://www.chp.ca.gov/html/amber-en.html"><img src="images/ca_master/amber_alert_on.gif" alt="Amber Alert is on. Please visit CHP's website for more information" width="580" height="57"/></a> </div> --> <!-- End Amber Alert --> <!-- **************************************************************** --> <!-- **************************************************************** --> <!-- Begin Middle Column Content - Put your primary page content here --> <h2>Annual Report</h2> <?php if(isset($_POST['Submit']) && $captcha_passed || $display_captcha == ''){ $display_captcha = 'display:none'; ?> <script type="text/javascript">displayCaptcha();</script> <?php }else{ ?> <?php if(isset($_POST['Submit']) && !$captcha_passed){ ?> <p style="font-weight:bold;color:red;font-size:16px">Please re-enter the CAPTCHA code.</p> <?php }else{ ?> <?php } ?> <div id="branches_info"> <form id="BranchesInfo" method="post" action="report_branches_test.php" onsubmit="return validateBranches(this);"> <fieldset> <p><strong>Institution Information</strong></p> <div> Report for Year: <?php echo $report_year ?><br /> Institution Name: <?php echo $institution_name ?><br /> Institution Code: <?php echo $institution_code ?><br /> <!--Street Address: <?php echo $street_address ?><br /> City: <?php echo $city ?><br /> State: <?php echo $state ?><br /> Zip Code: <?php echo $zip_code ?><br />--> </div> <p> </p> <p><strong>Branch Location</strong></p> <label for="branch_address" class="long">Street Address:</label> <input maxlength="50" type="text" name="branch_address" id="branch_address" value="<?php echo htmlentities($_POST['branch_address']);?>" /><br /> <div class="cleaner"></div> <label for="branch_city" class="long">City:</label> <input maxlength="20" type="text" name="branch_city" id="branch_city" value="<?php echo htmlentities($_POST['branch_city']);?>" /><br /> <div class="cleaner"></div> <label for="branch_state" class="long">State:</label> <select name="branch_state" id="branch_state" class="selectTwo"> <option value="" selected="selected">*Select your State*</option> <option value="NON" <?php if($_POST['branch_state'] == NON) echo 'selected';?>>Non US Resident</option> <option value="AL" <?php if($_POST['branch_state'] == AL) echo 'selected';?>> Alabama</option> <option value="AK" <?php if($_POST['branch_state'] == AK) echo 'selected';?>> Alaska</option> <option value="AZ" <?php if($_POST['branch_state'] == AZ) echo 'selected';?>> Arizona</option> <option value="AR" <?php if($_POST['branch_state'] == AR) echo 'selected';?>> Arkansas</option> <option value="CA" <?php if($_POST['branch_state'] == CA) echo 'selected';?>> California</option> <option value="CO" <?php if($_POST['branch_state'] == CO) echo 'selected';?>> Colorado</option> <option value="CT" <?php if($_POST['branch_state'] == CT) echo 'selected';?>> Connecticut</option> <option value="DE" <?php if($_POST['branch_state'] == DE) echo 'selected';?>> Delaware</option> <option value="FL" <?php if($_POST['branch_state'] == FL) echo 'selected';?>> Florida</option> <option value="GA" <?php if($_POST['branch_state'] == GA) echo 'selected';?>> Georgia</option> <option value="HI" <?php if($_POST['branch_state'] == HI) echo 'selected';?>> Hawaii</option> <option value="ID" <?php if($_POST['branch_state'] == ID) echo 'selected';?>> Idaho</option> <option value="IL" <?php if($_POST['branch_state'] == IL) echo 'selected';?>> Illinois</option> <option value="IN" <?php if($_POST['branch_state'] == IN) echo 'selected';?>> Indiana</option> <option value="IA" <?php if($_POST['branch_state'] == IA) echo 'selected';?>> Iowa</option> <option value="KS" <?php if($_POST['branch_state'] == KS) echo 'selected';?>> Kansas</option> <option value="KY" <?php if($_POST['branch_state'] == KY) echo 'selected';?>> Kentucky</option> <option value="LA" <?php if($_POST['branch_state'] == LA) echo 'selected';?>> Louisiana</option> <option value="ME" <?php if($_POST['branch_state'] == ME) echo 'selected';?>> Maine</option> <option value="MD" <?php if($_POST['branch_state'] == MD) echo 'selected';?>> Maryland</option> <option value="MA" <?php if($_POST['branch_state'] == MA) echo 'selected';?>> Massachussetts</option> <option value="MI" <?php if($_POST['branch_state'] == MI) echo 'selected';?>> Michigan</option> <option value="MN" <?php if($_POST['branch_state'] == MN) echo 'selected';?>> Minnesota</option> <option value="MS" <?php if($_POST['branch_state'] == MS) echo 'selected';?>> Mississippi</option> <option value="MO" <?php if($_POST['branch_state'] == MO) echo 'selected';?>> Missouri</option> <option value="MT" <?php if($_POST['branch_state'] == MT) echo 'selected';?>> Montana</option> <option value="NE" <?php if($_POST['branch_state'] == NE) echo 'selected';?>> Nebraska</option> <option value="NV" <?php if($_POST['branch_state'] == NV) echo 'selected';?>> Nevada</option> <option value="NH" <?php if($_POST['branch_state'] == NH) echo 'selected';?>> New Hampshire</option> <option value="NJ" <?php if($_POST['branch_state'] == NJ) echo 'selected';?>> New Jersey</option> <option value="NM" <?php if($_POST['branch_state'] == NM) echo 'selected';?>> New Mexico</option> <option value="NY" <?php if($_POST['branch_state'] == NY) echo 'selected';?>> New York</option> <option value="NC" <?php if($_POST['branch_state'] == NC) echo 'selected';?>> North Carolina</option> <option value="ND" <?php if($_POST['branch_state'] == ND) echo 'selected';?>> North Dakota</option> <option value="OH" <?php if($_POST['branch_state'] == OH) echo 'selected';?>> Ohio</option> <option value="OK" <?php if($_POST['branch_state'] == OK) echo 'selected';?>> Oklahoma</option> <option value="OR" <?php if($_POST['branch_state'] == 'OR') echo 'selected';?>> Oregon</option> <option value="PA" <?php if($_POST['branch_state'] == PA) echo 'selected';?>> Pennsylvania</option> <option value="RI" <?php if($_POST['branch_state'] == RI) echo 'selected';?>> Rhode Island</option> <option value="SC" <?php if($_POST['branch_state'] == SC) echo 'selected';?>> South Carolina</option> <option value="SD" <?php if($_POST['branch_state'] == SD) echo 'selected';?>> South Dakota</option> <option value="TN" <?php if($_POST['branch_state'] == TN) echo 'selected';?>> Tennessee</option> <option value="TX" <?php if($_POST['branch_state'] == TX) echo 'selected';?>> Texas</option> <option value="UT" <?php if($_POST['branch_state'] == UT) echo 'selected';?>> Utah</option> <option value="VT" <?php if($_POST['branch_state'] == VT) echo 'selected';?>> Vermont</option> <option value="VA" <?php if($_POST['branch_state'] == VA) echo 'selected';?>> Virginia</option> <option value="WA" <?php if($_POST['branch_state'] == WA) echo 'selected';?>> Washington</option> <option value="DC" <?php if($_POST['branch_state'] == DC) echo 'selected';?>> Washington, D.C.</option> <option value="WV" <?php if($_POST['branch_state'] == WV) echo 'selected';?>> West Virginia</option> <option value="WI" <?php if($_POST['branch_state'] == WI) echo 'selected';?>> Wisconsin</option> <option value="WY" <?php if($_POST['branch_state'] == WY) echo 'selected';?>> Wyoming</option> </select> <div class="cleaner"></div> <label for="branch_zip" class="long">Zip Code:</label> <input maxlength="10" type="text" name="branch_zip" id="branch_zip" value="<?php echo htmlentities($_POST['branch_zip']);?>" /><br /> <div class="cleaner"></div> <br /> <div id="captcha_box" style=" <?php echo $display_captcha; ?> "> <strong>*CAPTCHA: (Please enter the text found in the image below<br /> or specified in the audio link to validate the submission of your data.)</strong><br /> <img src="<?php echo captchaImgUrl();?>" alt="CAPTCHA" /><br /> <a href="<?php echo captchaWavUrl();?>">Listen To This</a><br /> <input id="captcha" type="text" name="captcha" size="20" /> </div> <p><input type="submit" name="Submit" value="Submit to Database" class="inputSubmit" /> <input type="button" value="Finished" onclick="location.href='report_thankyou.php'" class="inputSubmit" /><br /> <span style="font-style:italic">I declare under penalty of perjury under the laws of the State of California that the foregoing and all attachments are true and correct.</span></p> </fieldset> </form> </div> <?php } ?> <!-- End Middle Column Content --> <!-- **************************************************************** --> </div> </div> <!-- ********** Middle column content ends ********** --> <div class="cleaner"> </div> </div> <div class="cleaner"> </div> <?php include("ssi/footer.php"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/244547-need-help-hiding-captcha/ Share on other sites More sharing options...
WebStyles Posted August 11, 2011 Share Posted August 11, 2011 (I confess I only skimmed through half your code) but, since you're setting $captcha_passed to 1 after the first insert, you could set a $_SESSION variable at the same time so that you know the capture has been passed. You can even count the times it has been submitted and show the capture every 10 times (or whatever). // set the variable after $capture_passed to 1 if it doesn't exist yet or increment $_SESSION['captureCount'] = !isset($_SESSION['captureCount']) ? 1 : $_SESSION['captureCount']++; // use to decide if you should show capture again: only display capture if never used or every 10 times if( (!isset($_SESSION['captureCount'])) || ((isset($_SESSION['captureCount'])) && ($_SESSION['captureCount'] % 10 == 0)) ){ // show capture } Quote Link to comment https://forums.phpfreaks.com/topic/244547-need-help-hiding-captcha/#findComment-1256161 Share on other sites More sharing options...
dca_steve Posted August 12, 2011 Author Share Posted August 12, 2011 That makes sense - I'll give it a shot, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/244547-need-help-hiding-captcha/#findComment-1256505 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 Next time use code tags, its horrible to read that long code without them. Quote Link to comment https://forums.phpfreaks.com/topic/244547-need-help-hiding-captcha/#findComment-1256509 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.