/    Sign up×
Community /Pin to ProfileBookmark

processing huge checkbox form….. ?

Ahoy there everybody! I am new to forms, have made some simple email forms before, but man, this one is killing me.

Alright, before we go on: [url]www.airecastle.com/customized-package.html[/url]

As you can see, the user checks the boxes they are intersted in. Now, I want the options they select to be sent to them via the email form at the bottom of the page. I ONLY want the options they checked to be sent, and of course, organized nicely.

I know I should do a for loop for all the elements in there, but the problem I was running into was unique names of the checkboxes. “Options” in my following example was taken from a list box with ONE name, ya know?

[CODE]$options=$_POST[‘options’];
$msg.=”nOptions:”;
if ($options) for ($i=0;$i<count($options);$i++) $msg.= “n- $options[$i]”;
else $msg.=”n- None”;[/CODE]

For my for loop, I need a way to count the number of checkboxes there are so the loop can end. Then, of course, an if statement filtering out the checked from unchecked.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chazzyApr 18.2006 — try a different approach.

give every checkbox the same name="mycheckbox[]" which will create an array. then loop through the array and give them different values. IE a 2 night stay could be
[code=html]<input type="checkbox" name="checkbox[]" value="2nightstay" />[/code]
then just loop through
[code=php]
$boxes = $_POST['checkbox'];
for($i = 0;$i<length($boxes);$i++){
echo $i." has value ".$boxes[$i]."<br />n";
}[/code]


Also, the only ones sent back are the checked ones. Unchecked aren't sent via post.
Copy linkTweet thisAlerts:
@tokey666authorApr 18.2006 — Awesome! Thanks for the help! Got a problem though. (Of course, haha) My value attribute already contains the amount of the service/item. How would I go about storing that info and making the total if the value is the title instead? As you can see from the page, I already have the totals/update part running and would hate to change it.

Basically, I would want the email to read:

Checked Item1: $Price for 1

Checked Item5: $Price for 5

Checked Item23: $Price for 23

Total: $total price
Copy linkTweet thisAlerts:
@chazzyApr 18.2006 — What if your value was a pipe delimited list?

value = "Price|Name" then just break the value apart when processing?

or do you keep this stuff in a database? why not do a look up and use some clever sql to find out the total?
Copy linkTweet thisAlerts:
@tokey666authorApr 18.2006 — I thought about that, the database I mean. (Pipe delimited is a bit too advanced for me. I tried doing something like that when I took programming in college, but always failed miserably. ) If its the ONLY way, then I'll do it, ya know? This just seems too simple to drag a database into it.

There isnt another attibute to the input tag that I can store values in?
Copy linkTweet thisAlerts:
@balloonbuffoonApr 18.2006 — Its easy to do it like that ("Price|Name")...
[code=php]$value = "Price|Name";
$attr = explode("|",$value);
//now $attr[0]="Price" and $attr[1]="Name"
[/code]
But anyway...putting the price for the item in the page is not good. Someone could easily send a different price and end up getting an item for a couple cents or nothing! Of course, if a human will be looking at the order before it actually goes through, they can tell if the prices are right or wrong.

--Steve
Copy linkTweet thisAlerts:
@chazzyApr 19.2006 — you can create any sort of attribute/value pairs you want, since this is also XML (provided you're using XHTML) but then you can't read it like a form. using a database would be your best bet. i hate people who think that databases are only for very complex things. i wouldn't trust anything in an ecommerce solution that didn't run on a database, both as a consumer and a developer/implementor
×

Success!

Help @tokey666 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...