goltoof Posted July 12, 2011 Share Posted July 12, 2011 Why won't this form submit? When I hit submit the page just stays and doesn't submit anything to the db. It uses ajax to display the form (test.php) but the problem isn't the ajax just the way the php generates the form, i think. display.php <?php $q=$_GET["q"]; if ($q == true) echo '<table><form method="post" action="update.php" onsubmit="return udpate()">'; if ($q == "test") include 'test.php'; if ($q == "test2") include 'test2.php'; if ($q == true) echo '</table><input type="submit" value="Add Product" /></form>'; if ($q == false) echo ''; ?> test.php <?php echo '<tr><td>Product Category:</td><td><input type="text" name="prod_cat" size="" /></td></tr>'; echo '<tr><td>Model# </td><td><input type="text" name="model" size="" /></td></tr>'; echo '<tr><td>List Price </td><td><input type="text" name="price_list" size="" /></td></tr>'; ?> update.php <?php include ('link.php'); $id = $_POST['']; $prod_cat = $_POST['prod_cat']; $model = $_POST['model']; $price_list = $_POST['price_list']; $query= "INSERT INTO product_specs (ID, prod_cat, model, price_list ) VALUES ('NULL', '".$prod_cat."', '".$model."', '".$price_list."') "; mysql_query($query) or die ('Error updating database: ' . mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/ Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 So when you submit your form, you aren't even taken to update.php? What does your update() function look like? Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241896 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 What does your update() function look like? It's just a simple alert and page refresh function update() { alert("Database updated."); window.location.reload(true); } I don't think that's the problem here though because the html (echoed in php) works fine in it's own page but it doesn't work when created with display.php and test.php Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241899 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 Just in case, here's index.php, containing the ajax that populates the "getDisplay" div with display.php and test.php: <script type="text/javascript"> function getDisplay(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("getDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","display.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <div id="header"> <div id="form"> <form> <select onchange="getDisplay(this.value)"> <option value="">Select product category</option> <option value="test">Test</option> <option value="test2">Test 2</option> </select> </form> </div> </div> <div id="getDisplay"> <div id="info"><!-- display.php & test.php appear here --!></div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241901 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 you said it doesn't submit anything into your db, but does it take you to update.php? Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241903 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 you said it doesn't submit anything into your db, but does it take you to update.php? neither Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241904 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 what does a "view source" in your browser show? Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241906 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 what does a "view source" in your browser show? Source looks like this... When "test" is selected, display.php populates it along with test.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Update</title> <link rel="stylesheet" href="style.css" type="text/css"> <script type="text/javascript"> function getDisplay(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("getDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","display.php?q="+str,true); xmlhttp.send(); } </script> <script language="javascript"> function update() { alert("Database updated."); window.location.reload(true); } </script> </head> <body> <div id="header"> <div id="form"> <form> <select onchange="getDisplay(this.value)"> <option value="">Select product category</option> <option value="select-test">Test</option> </select> </form> </div> </div> <br /> <div id="getDisplay"> <div id="info">Product info listed here.</div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241907 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 make sense to anyone? Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241984 Share on other sites More sharing options...
djlee Posted July 12, 2011 Share Posted July 12, 2011 the get display div that is populated is outside of your form tags. therefore the submit is outside your form tags when the html is inserted. I'd imagine thats the issue ? Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241987 Share on other sites More sharing options...
goltoof Posted July 12, 2011 Author Share Posted July 12, 2011 the get display div that is populated is outside of your form tags. therefore the submit is outside your form tags when the html is inserted. I'd imagine thats the issue ? If you look back "test.php" and "display.php" are both set inside of the "getDisplay" div. So the entire form is intact inside the same div. There are two forms here, one is the select form which triggers the AJAX to display the form that is created by display.php and test.php. The AJAX (select) form works fine, and the form inside of the getDisplay div appears fine, but it won't submit. Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1241990 Share on other sites More sharing options...
djlee Posted July 12, 2011 Share Posted July 12, 2011 echo '<table><form method="post" action="update.php" onsubmit="return udpate()">'; the function name in the onsubmit is wrong Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1242004 Share on other sites More sharing options...
goltoof Posted July 13, 2011 Author Share Posted July 13, 2011 echo '<table><form method="post" action="update.php" onsubmit="return udpate()">'; the function name in the onsubmit is wrong Good catch, but still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/241824-php-generated-form/#findComment-1242275 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.