karenn1 Posted June 10, 2009 Share Posted June 10, 2009 Hey everyone, I have a page where users can complete an inventory form of the contents of their parcel. I've set it up that the user must enter a number for the amount of items, then clicks on next. This returns the page, using that number and displaying the same amount of rows. Each row contains three fields (Date Purchased, Description, Value), thus given an inventory grid for the user to fill in. Here's the code: <? $i = 0; while ($i < $_POST['number']) { ?> <tr> <td valign="top" bgcolor="#F5F5F5"><input name="date_purchased[]" type="text" id="value" size="20" /> <br /> </td> <td valign="top" bgcolor="#F5F5F5"><textarea name="description[]" id="description" cols="20" rows="2"></textarea></td> <td valign="top" bgcolor="#F5F5F5"><strong><font color="#FFCCFF" size="2" face="Arial, Helvetica, sans-serif"> <span class="quote-blue-text"> R <input name="value[]" type="text" id="value" size="10" /> </span></font></strong></td> </tr> <? $i++; } ?> And this is the code to store the values: $date_purchased = $_POST['date_purchased']; $description = $_POST['description']; $value_p = $_POST['value']; $p = 1; while ((list($key, $value) = each ($date_purchased)) && (list($key2, $value2) = each ($description)) && (list($key3, $value3) = each ($value_p))) { $sql3 = "INSERT INTO public.inventory (date_purchased, description, value, number_of_items, waybill_number) VALUES ( '".$value."', '".$value2."', '".$value3."', '".$_POST['number']."', '".$id."' )"; $result3 = pg_query($sql3); $p++; } All of this works perfect. The only problem I have is doing field validation. Can anyone please help with this? I don't want any of the fields in the array to be empty. Can this be done? Thanks! Karen Link to comment https://forums.phpfreaks.com/topic/161635-fields-in-array-validation/ Share on other sites More sharing options...
karenn1 Posted June 10, 2009 Author Share Posted June 10, 2009 Can anyone please help with this? Thanks in advance! Karen Link to comment https://forums.phpfreaks.com/topic/161635-fields-in-array-validation/#findComment-853078 Share on other sites More sharing options...
haku Posted June 10, 2009 Share Posted June 10, 2009 if(trim($_POST['field']) == '') { die("field cannot be empty"); } This is very simplified, but should get you started. Link to comment https://forums.phpfreaks.com/topic/161635-fields-in-array-validation/#findComment-853119 Share on other sites More sharing options...
karenn1 Posted June 11, 2009 Author Share Posted June 11, 2009 Hey haku, Thanks for your reply. I tried using something similar but I couldn't get it to work. This code just takes the posted value. How can I get it to tie in with the array and check if $value, $value2 and $value3 in the while loop is valid? Thanks! Karen Link to comment https://forums.phpfreaks.com/topic/161635-fields-in-array-validation/#findComment-853801 Share on other sites More sharing options...
karenn1 Posted June 12, 2009 Author Share Posted June 12, 2009 Can anyone else please please help? I'm really scratching my head on this one. Karen Link to comment https://forums.phpfreaks.com/topic/161635-fields-in-array-validation/#findComment-854415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.