Jump to content

Fields in Array Validation


karenn1

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.