/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How to process a Invoice form?

Hi, I’m having a problem. I’m doing an Invoice system. So basically the user can enter the Item name, cost, quantity and total will be auto calc using javascript.

Currently, I’m adding a iteration behind each input to differentiate them. E.g.

[CODE]<input type =”text” name = “Item<?=$i?>”/>[/CODE]

$i is an iteration using for loop.

My problem is, how to process it at the php side?

$itemName = $_POST[‘Item’];

I can’t possibly hardcode it for the name inside post to be $_POST[‘Item1’], $_POST[‘Item2’], $_POST[‘Item3’]….
If there are more than 10 items, it’s too long. Any help? ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJun 24.2010 — if you give the inputs the same name, they should be sent to the $erver as an array when you submit the form and you can then loop through the array on the $erver as you would with any other array.

[CODE]
<input type ="text" name = "Item[]" />

<input type ="text" name = "Item[]" />

[/CODE]
Copy linkTweet thisAlerts:
@monstez88authorJun 24.2010 — So my $erver side code should be

[CODE]$item = $_POST['Item[]']; [/CODE]
Copy linkTweet thisAlerts:
@tirnaJun 24.2010 — Your client side code could be something like this:

[CODE]
<form action="formProcessor.php" method="post" >

<input type="text" name="myTxt[]" />
<input type="text" name="myTxt[]" />

<input type="submit" value="submit" />

</form>
[/CODE]


and formProcessor.php could be something like this:


[code=php]
<?php

//assing the values from the textboxes to an array
$inpArray = $_POST['myTxt'];

//loop thru the array to display all the textbox values
foreach($inpArray as $key => $value) {
echo $key.' '.$value.'<br />';
}

//display the value in the first etxbox
echo 'value of first input = '.$inpArray[0];

?>
[/code]
Copy linkTweet thisAlerts:
@monstez88authorJun 24.2010 — Hey thanks! That really worked out. Thanks lots! ?
Copy linkTweet thisAlerts:
@tirnaJun 24.2010 — no problem - happy to help ?
Copy linkTweet thisAlerts:
@iahneJun 29.2010 — that's tirna's final signature "no problem - happy to help ?"
×

Success!

Help @monstez88 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...