matthewst Posted March 25, 2010 Share Posted March 25, 2010 I have a form that submits to itself (I know it should submit to a handler but that's the way it was when I took over.). I've had to add a dynamic dropdown menu to the page. The dropdown works like it should except now the page submits every time it loads. <? include('include/user_check.php'); include('include/db_con.php'); $id = $_SESSION['track_id']; $dest_email='[email protected]'; set_time_limit ( 0 ); //error_reporting(E_ALL); if($_POST['submit']) { blah blah php stuff javascript var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_quote_num.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } start of form <form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="FormName" onSubmit="MM_validateForm('company','','R','address','','R','city','','R','RisNum','phone','','R','size','','R','ad_num','','R','quote_num','','R');return document.MM_returnValue;return Form1_Validator(this)"> new dropdown (the disabled dropdown is replaced by the working one once a selection is made in another menu [/code]<td> <div id="txtHint"> <select name='quote_num' class='formTextbox' size='1' disabled='disabled'> <option value=''>Select from other dropdown first</option> </select> </div> </td>[/code] get_quote_num.php page <?php $q=$_GET["q"]; include('include/db_con.php'); <select> blah blah this works fine </select> back to the form <input type="submit" class="formTextbox" name="submit" value="Submit"> It doesn't submit when I use the dropdowns. Only when it loads. When I actually click the submit button it submits twice! Link to comment https://forums.phpfreaks.com/topic/196491-form-with-xmlhttp-submits-every-time-it-loads/ Share on other sites More sharing options...
matthewst Posted March 25, 2010 Author Share Posted March 25, 2010 As it turns out I'm an idiot. After checking the database and NOT seeing a billion new records I realized it was just sending me the notification email. So, I moved mail() to the inside of my if($_POST brackets. All is now right with the world. Link to comment https://forums.phpfreaks.com/topic/196491-form-with-xmlhttp-submits-every-time-it-loads/#findComment-1031762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.