Jump to content

submit dropdown


searls03

Recommended Posts

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????

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>  
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.