Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/270315-php-and-html-form-tag-problem/
Share on other sites

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

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.