Hi
Im trying to attach an "id" into a textfield?
I plan to do a form like this
ItemID | Name | Price
1 | pen | <textfield>
2 | paper | <textfield>
3 | ink | <textfield>
<button>
I was hoping if I could attach the itemid with the textfield, it would be easier to distinguish when Im about to insert the values from the textfield in the database
How to attach ID(from data in DB) into a textfield?
Moderator: General Moderators
Re: How to attach ID(from data in DB) into a textfield?
If you are using a single form for each item.. Just pass the item ID along in a hidden input field.
If you are using a single form for multiple items then you will have to make your form inputs like this..
[text]<input type="text" name="price[itemIDhere]:">[/text]
Then PHP will parse your form into a multidimensional $_POST array for you to deal with.
If you are using a single form for multiple items then you will have to make your form inputs like this..
[text]<input type="text" name="price[itemIDhere]:">[/text]
Then PHP will parse your form into a multidimensional $_POST array for you to deal with.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: How to attach ID(from data in DB) into a textfield?
Thanks for the reply 
When it is sent to the PHP script that handles validation, how do I "cut" the array so I could validate each item entered?
When it is sent to the PHP script that handles validation, how do I "cut" the array so I could validate each item entered?
Re: How to attach ID(from data in DB) into a textfield?
do a print_r($_POST) to see what the post array looks like.
Actually, I would set up the form like this though
Where 1, 2, and 3 are the respective item ID numbers and price and name are the fields you are passing. Adjust it to fit your situation.
Then, to analyze the post input, you could do
Actually, I would set up the form like this though
Code: Select all
<input type="text" name="item[1][price]">
<input type="text" name="item[1][name]">
<input type="text" name="item[2][price]">
<input type="text" name="item[2][name]">
<input type="text" name="item[3][price]">
<input type="text" name="item[3][name]">Then, to analyze the post input, you could do
Code: Select all
<?php
if (!empty($_POST['item']))
{
foreach ($_POST['item'] AS $itemID => $details)
{
echo 'Item ID: ' . $itemID . ' Price: ' . $details['price'] . ' Name: ' . $details['name'] . '<br />';
}
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.