searls03 Posted February 5, 2012 Share Posted February 5, 2012 so I need to know how to make this drop down include hidden fields in it: <form id="myform1" method="POST"> <select onchange="document.getElementById('myform1').submit()"> <?php //start the table, and the row. // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <option><input type="text" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="text" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /><?php echo $product; ?> </option> <?php // start a column } ?> </select> <noscript> <input type="submit" value="Go" id="Submit1" /> </noscript> </form> Kind of like is shown.......so that each option has an id. then I need it to submit to this code: <script type="text/javascript"> $(document).ready(function(){ $(".myform1").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('process.php', $(".myform1").serialize(), function(data) { $("#price").load("index.php #price");$("#total").load("index.php #total"); }); } }); }); </script> . Can anyone help? I hope this makes sense???? Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/ Share on other sites More sharing options...
Psycho Posted February 5, 2012 Share Posted February 5, 2012 I hope this makes sense???? No, it doesn't. You can't put "input" fields into the options of a select list. Besides,you are going about this entirely wrong. You should not put information such as price into a hidden field and use that in your processing logic. It is too easy for someone to modify those values. So, for example, a user could place an order for a product and submit the page such that the price value is $0.01. Instead you should only need to pass the ID of the product. Then, when you process the form you can get the price (or any other information for the product) from your database. That way you are certain to be using the correct information. So, based upon what you have above you would only want to query the name and id of the products (don't use * in your SELECT statements) and then use those two values for the value and label of the options. Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314867 Share on other sites More sharing options...
searls03 Posted February 6, 2012 Author Share Posted February 6, 2012 ok, how do I make it work with the submission code though? Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314900 Share on other sites More sharing options...
searls03 Posted February 6, 2012 Author Share Posted February 6, 2012 it's not technically the submission code, it is the code that leads to the submission code without the page refrehing..... Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314906 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 they're saying to create a mysql db have a table with products in it id | price | description | whatever 432 | 34.00 | trinket | extra info.. and so your input would just be <select name="buyit"> <option value="432">Trinket</option> </select> then before submitting your code, get the price from the database: <?php include('mysqlconnect.php'); $sql = 'GET * from table WHERE id ='. mysql_real_escape_string($_POST['buyit']); ?> <script type="text/javascript"> $(document).ready(function(){ $(".myform1").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('process.php', $(".myform1").serialize(), function(data) { $("#price").load("index.php #price");$("#total").load("index.php #total"); }); } }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314913 Share on other sites More sharing options...
searls03 Posted February 6, 2012 Author Share Posted February 6, 2012 I know what they were saying. I am just going to have to make a different submission page, which i was hoping not to do, but oh well. Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314914 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 you could make a separate include file with an array instead, and just update values in that. then include it, and have it's unique id match the id in the table so in a separate file <?php $products = array ( '432'=>array('price'=>'5', 'description'=> 'more info...') , '433'=>array('price'=>'17', 'description'=> 'less info...') ); ?> or you could make the option value a serialized array, and then just unserialize it after it's been submitted Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1314920 Share on other sites More sharing options...
Psycho Posted February 6, 2012 Share Posted February 6, 2012 I know what they were saying. I am just going to have to make a different submission page, which i was hoping not to do, but oh well. Why do you need a separate submission page? The only thing you should be submitting is the ID. You should never include variables such as price as part of your submission since you already have that data in your database. The page that you submit to (i.e. the processing page) should take the product ID, query the DB for additional data that you need and then perform whatever processes you need. Quote Link to comment https://forums.phpfreaks.com/topic/256488-submit-dropdown/#findComment-1315009 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.