varun7952 Posted November 5, 2012 Share Posted November 5, 2012 i have two different php file one is header and one is poll both php file has form tag i works fine but when i click on vote button in poll it redirect to top of the page without showing any result and submitting form so i was looking for error and when i remove form tag in header poll start working fine so i think its form tag problem header file form :- <form method="get" action="http://www.google.com/search"> <fieldset> <legend>Site Search</legend> <input type="text" name="q" size="31" maxlength="255" value="Google Search" /> <input type="submit" value="Search" name="go" id="go"/> </fieldset> </form> and poll form :- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false" method="post"> <div id="mainContainer"> <div id="mainContent"> <?php $pollerId = 2; // Id of poller ?> <!-- START OF POLLER --> <div class="poller"> <div class="poller_question" id="poller_question<?php echo $pollerId; ?>"> <?php // Retreving poll from database $res = mysql_query("select * from poller where ID='$pollerId'"); if($inf = mysql_fetch_array($res)){ echo "<p class=\"pollerTitle\">".$inf["pollerTitle"]."</p>"; // Output poller title $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error()); // Find poll options, i.e. radio buttons while($infOptions = mysql_fetch_array($resOptions)){ if($infOptions["defaultChecked"])$checked=" checked"; else $checked = ""; echo "<p class=\"pollerOption\"><input$checked type=\"radio\" value=\"".$infOptions["ID"]."\" name=\"vote[".$inf["ID"]."]\" id=\"pollerOption".$infOptions["ID"]."\"><label for=\"pollerOption".$infOptions["ID"]."\" id=\"optionLabel".$infOptions["ID"]."\">".$infOptions["optionText"]."</label></p>"; } } ?> <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a> </div> <div class="poller_waitMessage" id="poller_waitMessage<?php echo $pollerId; ?>"> Getting poll results. Please wait... </div> <div class="poller_results" id="poller_results<?php echo $pollerId; ?>"> <!-- This div will be filled from Ajax, so leave it empty --></div> </div> <!-- END OF POLLER --> <script type="text/javascript"> if(useCookiesToRememberCastedVotes){ var cookieValue = Poller_Get_Cookie('dhtmlgoodies_poller_<?php echo $pollerId; ?>'); if(cookieValue && cookieValue.length>0)displayResultsWithoutVoting(<?php echo $pollerId; ?>); // This is the code you can use to prevent someone from casting a vote. You should check on cookie or ip address } </script> </div> <div class="clear"></div> </div> </form> can you please tell me where is the problem is i stuck badly in this problem Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/ Share on other sites More sharing options...
cyberRobot Posted November 5, 2012 Share Posted November 5, 2012 I think the problem comes from the Javascript code below: <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a> Try changing the document.forms part to: document.forms[1] As a side note, I would recommend that you avoid using $_SERVER['PHP_SELF'] as the form action. For more information, see: http://seancoates.com/blogs/xss-woes Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390350 Share on other sites More sharing options...
varun7952 Posted November 5, 2012 Author Share Posted November 5, 2012 that wont work thx for ur answer please review it again Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390356 Share on other sites More sharing options...
varun7952 Posted November 5, 2012 Author Share Posted November 5, 2012 I think the problem comes from the Javascript code below: <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a> Try changing the document.forms part to: document.forms[1] thanks for your answers that change make poll run but it still redirect to top of the page please tell me so i can modify my script thankyou very much Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390357 Share on other sites More sharing options...
cyberRobot Posted November 5, 2012 Share Posted November 5, 2012 thanks for your answers that change make poll run but it still redirect to top of the page please tell me so i can modify my script thankyou very much Does the form need to submit back to the server...or does everything that needs to happen take place in Javascript? If the form data doesn't need to go back to the server for processing, try moving the "return false" part after the call to castMyVote(). <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0]); return false;"><img src="images/vote_button.gif"></a> If that doesn't work, you may need to incorporate the "return false;" into the castMyVote() function. Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390363 Share on other sites More sharing options...
varun7952 Posted November 5, 2012 Author Share Posted November 5, 2012 Does the form need to submit back to the server...or does everything that needs to happen take place in Javascript? If the form data doesn't need to go back to the server for processing, try moving the "return false" part after the call to castMyVote(). <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0]); return false;"><img src="images/vote_button.gif"></a> If that doesn't work, you may need to incorporate the "return false;" into the castMyVote() function. thx u very much it really works u r genius thx u very much Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390413 Share on other sites More sharing options...
cyberRobot Posted November 5, 2012 Share Posted November 5, 2012 No problem, glad to help! Quote Link to comment https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/#findComment-1390434 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.