PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Now, I need $check_msg and $txt_msg to be shown in the same line in the email. So if $check_msg is 10 and $txt_msg is Pancakes, it will come up in the email as "10 Pancakes". Not:
10
Pancakes
(with a line break)
I realise this might be very basic, but I have tried for many hours to do it without success. Any help will be appreciated.
Last edited by sk8bft on Sat Jan 03, 2009 7:35 pm, edited 2 times in total.
I think problem is that each $_POST['check'] value is appended with newline, so at the end it is "10\n Pancakes\n", which I thought was unwanted.
If it's so, then instead of foreach loops use
$check_msg = implode($_POST['check'], "\n"); //Now all values except last will be appended with new line
$txt_msg = implode($_POST['txt'], "\n"); //same
Yes! That's exactly what I was looking for. I have tested it with three checkboxes/textfields now and it works just the way I need it to. Didn't understand all of the coding, though, but I will read through the php manual. Thank you!
There was one of each of check and txt so it worked with two variables; your third won't always be there. If there's only one then the loop will only go through once - then, since it ran out of drop it will stop.
How does drop work with check? Meaning, how do you know that "w/Chocolate" belongs to Pancakes and not Waffles?
(PS: I'll add comments on the next version of the code.)
How does drop work with check? Meaning, how do you know that "w/Chocolate" belongs to Pancakes and not Waffles?
I attached a picture, is that what you meant? It's a non graphical version, but you can imagine there will be up to 40 different dishes, where you choose what kind of meat you want for some dishes etc (or if you want chocolate or ice cream on the pancakes - nevermind if someone want both, in the real website the choices will be chicken/beef/scampi etc)
However I guess it's possible to avoid this problem by adding radio button groups (or dropdowns) to each dish (even those with only one choice of meat), but it wouldn't be as smooth
[edit]
There might however be problems if someone wants to order 5 of the same dish, but with different meat (2 w/chicken and 3 w/beef). Ungh, this gets a little more complicated than I first expected
I meant how can the PHP know what goes where, but if it's getting complicated already...
Instead of grouping stuff by what it is (checkbox, name, extras) group by item. So $_POST["food"][0] would be an array of check=>1, item=>Pancakes, amount=>3, extra=>Chocolate, [1] would be check=>1, item=>Waffles, amount=>2.
Then the code to display that again is easy:
I've been reading about arrays since you posted but I can't understand how to group this correctly by item. I found several tutorials on how to do this with one dropdown, but I can't find anything about something that looks close to this. Should the checkbox, text field and dropdown be grouped like this:
Yes, fantastic! I had to do a small change in the php code also as I wanted the item names as from the checkbox values. So i replaced ["item"] with ["check"] and now it seems to be working fine!