Topic: checkboxes and $_POST, send HTML mail (Read 1854 times)
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« on: Aug 28, 2006, 05:39:18 am »
Hello all, Olaf ! Been hacking away on the user_access class and extended it to suit my specific needs, some changes and some improvements that suited my taste ! Very nice that this oo c++ style feature is now a part of php, makes it quiet useful !! My question is trivial (i am sure) as usual. How do I check a checkbox after reading the db and finding a value "true" or "1" ? As opposed to "" or false if you will ?? <input type=CHECKBOX name="architect" value="1" /> is y box , simple as it was , and my input fields are <TD width="414"><INPUT TYPE="text" NAME="name" SIZE="30" value="<?php echo (isset($_POST['name'])) ? $_POST['name'] : "" ?>"></TD> , working quiet well of course !! Anyone real good at the php/html html/php mixing when it comes to the checkbox scenario above ?? Secondly, sending HTML mail, are there templates one can use to avoid a lot of HTML typing for the body, hate html...sorry..just can't wrap my small swedish brain around it late at night...(yepp I am planning to write yet another function to your class Olaf ) Want to avoid extensive (in my case) typos and html tag consfusion !!??
Thanks a lot Salut Anders
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Aug 28, 2006, 08:29:35 am »
Hi Anders,
You understand that I don't answer the post at phpclasses dot org... About the checkbox, the problem is that the check doesn't exists in the POST array if not checked, I solve this most of the time like this:
About the html mail, you're right the current mails are not so fine, I have almost finished the html version of my mailer class and I will use this class inside access_user in future version's. I wrote already in my own project a version where all mail's are written via mail templates. I will add this as important future update to the development list.
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« Reply #2 on: Aug 28, 2006, 09:13:09 am »
Ahaa !! I knew I had missed some important part of the story ! Thank you, most helpful indeed ! I took a shot at it through a if ($new_user->mycheckboxvalue == 1) etc etc and then depending on whether the logic produced true or false I would do a checkbox checked html tag...messy it did not look good and then the whole page kind'a got skewd ...he he..sorry ! So, to see if you smart guys and gals had a smoother solution I asked ! Yes, I am on the clear now that phpclasses is not where one can find your excellent supportive comments...I think I know why.. ! I am impressed with the breath of your knowledge and your persistent support !! I think I will take a shot at the html....but had to ask, lazy as I am...terrible, yes I know.... thank you Olaf !! Salut Anders
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Aug 28, 2006, 09:44:42 am »
you're welcome...
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« Reply #4 on: Aug 28, 2006, 11:19:06 pm »
Worked beatuifully ! Excellent ! I also added a function in ext_user_profile.php to display the checkboxes on update_user_profile.php that I collect on my input form. Basically just build the html string and add the checked key word or not. However, there is a small problem doing this. If the update_user_profile.php page receives a check box "checked", all is well, but if I uncheck a checkbox, do a "Save (profile)" the $_POST breaks with the message "Notice: Undefined index: mycheckboxname in /home/server21/www/a-website/update_user_profile.php on line 17. Think I need to print the html string I built for the checkbox, something is going on there that is not ok.....by the way, this html build stuff is going to work well with my email later on since I am asked to send the admin an email with user info on registration....hey this will be pretty cool ! mvh Anders
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« Reply #5 on: Aug 28, 2006, 11:22:09 pm »
Hold on a second..you mentioned that if the checkbox is "un"-checked, there is nothing in the $_POST string stored......nothing meaning what it is deleted...hmmm..looks like it since it is complaining of no or an undefined index...well, I guess I should read the manual....lazy as I am....
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« Reply #6 on: Aug 29, 2006, 07:33:48 am »
Well, I finally got around the annoying $_POST error in update_user_profile.php. In short and I am sure I have done something really ugly here (as I said need to read the bloody manual once and for all..), the checkboxes do not render anything, zilt when not checked, so the subsequent save_user_date() broke when I unchecked any of my boxes on the update page. I wrote a small function that checked for anyting in the $_POST['mycheckboxvar'] and if nothing there I gave it a default value to go and do the UPDATE with i.e mycheckboxval='whatever', instead of a checked value mycheckboxval='checked'. I tried to make the call right inside the save_user_date(), but was not too successful. So, that was that in short, wrote an additional function to build the checkboxes onthe page, similar to the form thing you wrote Olaf, now I can use this entire page now for a pretty nifty HTML mail . Well at anyrate, thought I mention this little checkbox thingi here, I am sure there is an elegant way to solve this....than what I did...as I said..where's that manual now...grrr...this $_POST $_GET $_REQUEST etc, takes a bit of time to get used to....my head is coming off....need to hit the hay...it is late here in California....later all ! Anders
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #7 on: Aug 29, 2006, 09:30:55 am »
maybe you like this class too, its possible to validate text fields and and also radio's and checkboxes:
Chicken-run Manager
Gender:
Posts: 9
62 credits Members referred : 0
« Reply #8 on: Aug 30, 2006, 08:33:02 am »
I will go and look Olaf thanks !! I am getting the php bug.....
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374