Jump to content

Inconsistent form issue using PHP and javascript


galvin

Recommended Posts

This might not be enough info for anyone to help with but I'm taking a chance because I'm at my wits end.

 

I have this relatively simple form on a page called "createquiz.php" which has a select dropdown for every row in the table which triggers the form to submit when an option is chosen.  It is then sent to "move.php" to manipulate the data.  The gist is that  users can go to row 4 (for example) and choose "2" from the drop down menu and it will go to move.php which will then update the id of row 4 to now be 2.  Basically just reordering the rows in the table.

 

The weird thing is that when the "option" chosen has a value LESS THAN the value of $info['answerid'] for the chosen row, the form submits fine to move.php (like my example above going from 4 to 2.

 

However, if the "option" chosen has a value GREATER THAN the value of $info['answerid'] for the chosen row (like if the user tried to move row 4 to row 7), the form doesn't submit to move.php and instead the page refreshes with a super weird URL like this...  "createquiz.php?move=3&submitthisform=submit&hidden=move&numanswers=3#".

 

I have no code anywhere the tries to build a URL anything like that, so something is going very wrong. It looks like it's taking all of the "names" from my form code below and throwing them into a URL.

 

With this minimal info, just curious if anyone has any idea what type of problem in code could lead to this weird type of URL?

 

FYI, the code that gets the values for $_GET['quizid'] and $info['answerid'] is not shown, but I'm positive that is all working fine so I don't think it's important in regards to this issue, especially because when the problem happens, it's not even getting to the point where it tries to post to that URL.

 

<form method='post' action='move.php?quizid={$_GET['quizid']}&answerid=" . $info['answerid'] . "'>
						<select name='move' onChange='this.form.submit();'>    <option value='x' >Move to...</option> ";
						for($i=1; $i<=$lastid;$i++) {
						 echo "<option value='$i'>$i</option>";
						}	
						echo "</select>
						<input type='hidden' name='submitthisform' value='submit' /><input type='hidden' name='hidden' value='move' /><input type='hidden' name='numanswers' value='$lastid' />
						</form>

Link to comment
Share on other sites

You either have something else going on in your form, such as nested form tags, which is invalid, or the move.php page you are submitting to is redirecting back to the form with that unexpected URL.

 

You would need to post enough working code that produces/reproduces the symptom. Just the small part you did post doesn't reproduce the problem.

Link to comment
Share on other sites

Not that you care, but I found that the form code I posted in this forum was inside of another unnecessary form that had a blank action and onChange='this.form.submit();' was submitting to the this other "parent" form, instead of the "child" form.

 

I have no idea why sometimes it would submit the "child" form and sometimes it submitted the "parent" form, but I guess it's not important now, because I removed the "parent" form (which is unnecessary, at least at this point) and the everything works all the time now.

 

Just weird.

 

Link to comment
Share on other sites

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.