I'm planning out a project and can't seem to figure out the best way to go about it. I will have a form that will have several fields, some will be drop down menus and that form will allow someone to select various choices to build a particular package. That is the part I'm having trouble with. Once all of the selections have been made and the form is submitted, it will send a line by line price quote with a total at the end. It's easy to get the amounts or the info into that email, but how can I put them both? For example, lets use a rocketship as an example:
Engine
option 1 - Solid fuel ($1,000)
option 2 - Nuclear fuel ($5,000)
option 3 - Ion fuel ($10,000)
And then when the form is submitted, the line item for this would be something like:
Other item info and prices here
Engine: Nuclear fuel ($5,000)
Other item info and prices here
Total: $35,000
Hopefully my explaination makes sense.
How would I create a form that calculates a total
Moderator: General Moderators
-
someguyhere
- Forum Contributor
- Posts: 181
- Joined: Sun Jul 27, 2008 3:24 pm
Re: How would I create a form that calculates a total
You said it was simple to get the amounts or the info into the email. I assume you've got different code to put both of those into the email body. Why not just run both those snippets so both pieces of information get put in the email body?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
someguyhere
- Forum Contributor
- Posts: 181
- Joined: Sun Jul 27, 2008 3:24 pm
Re: How would I create a form that calculates a total
Because each drop down will have several options. I can assign a value to each option in the html, but it would either be the item info or the item price, not both as two seperate bits of info.
Re: How would I create a form that calculates a total
Are you asking how to extract the dollar amount from a string, like "Nuclear fuel ($5,000)"? You could do it in several ways, like finding the substring that begins after the dollar sign, then terminating it before the closing quote:Then you'd probably want to eliminate the comma. It all depends on how you're formatting the data.
You could do it, no doubt, also with regex. But I've never gotten proficient with regex, so I'll leave that to someone else.
But the better way to do it, I'd think, would be to handle the dollar amounts separately, as numbers, combining them with the rest of the description when you form the strings for display.
Code: Select all
$x="Nuclear fuel ($5,000)";
$dollar=strpos($x,"$");
$quote=strpos($x,")");
$num=substr($x,$dollar + 1,$quote - $dollar);You could do it, no doubt, also with regex. But I've never gotten proficient with regex, so I'll leave that to someone else.
But the better way to do it, I'd think, would be to handle the dollar amounts separately, as numbers, combining them with the rest of the description when you form the strings for display.