the forms in my onlinestore have looked like this in the past:
<form action="cart.php" method="post">
<input type="hidden" name="article_number" value="12345">
<input type="hidden" name="article_name" value="T-Shirt Summer 2015">
<input type="hidden" name="price" value="19.00">
<select name="size"><option>S<option>M<option>L</select>
<select name="colour"><option>black<option>white</select>
<input type="submit" value="Add to cart">
</form>
The cart.php just put the data into a session without any validation. As you can see it would be very easy to cheat with the form (save local, change price to 9.00, add colours that doesn't exist in reality etc.
So my new idea was this:
<form action="cart.php" method="post">
<input type="hidden" name="article_number" value="12345">
<select name="size"><option>S<option>M<option>L</select>
<select name="colour"><option>black<option>white</select>
<input type="submit" value="Add to cart">
</form>
I've removed the name of the article and the price to avoid manipulations here.
So what's next? Best way to validate the data?
if(!empty($_POST['article_number']))
article_number
is validif(in_array($_POST['colour'], explode(",",$row['colours'])))
if(in_array($_POST['size'], explode(",",$row['sizes'])))
Do i need to do more validating? trim()
? I'm using PDO...
Thanks!