ilikephp Posted May 20, 2009 Share Posted May 20, 2009 hello all!! How can I force the checkbox no to be erased? I am using this code below but it is not working <input name="topic1" type="checkbox" id="topic1" value="<?php if (isset($_POST['VB.NET'])) echo $_POST['VB.NET']; ?>" /> Quote Link to comment Share on other sites More sharing options...
irvieto Posted May 20, 2009 Share Posted May 20, 2009 Hi. I do not understand the question. What do you mean with erase the checkbox? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 In order for a checkbox to be ticked, you don't set it's value, you set checked="checked". You might like to check out my tutorial on checkboxes and databases: http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database Quote Link to comment Share on other sites More sharing options...
ilikephp Posted May 20, 2009 Author Share Posted May 20, 2009 Sorry for not clarifiying! I meant that for the field name: when I enter a name, and I click submit or accept, I need to see my form again, so the names are not erased because I put: <input type="text" name="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>"> I need to do the same for the checkboxes. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 In order for a checkbox to be ticked, you don't set it's value, you set checked="checked". You might like to check out my tutorial on checkboxes and databases: http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database Quote Link to comment Share on other sites More sharing options...
ilikephp Posted May 20, 2009 Author Share Posted May 20, 2009 thx for the link, it is well organised and easy to understand; but I did not find a solution to my problem :S I am adding this script below for the fields, what should I add for the checkboxes? value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 Ok. So you know how to make a checkbox ticked by default, right? You also know how to check to see if it was checked in the POST array, right? So...What do you think you need to do? Quote Link to comment Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 <input name="topic1" type="checkbox" id="topic1"<?PHP echo (!empty($_POST['topic1']))?" checked=\"checked\"":NULL; ?>> Quote Link to comment Share on other sites More sharing options...
ilikephp Posted May 21, 2009 Author Share Posted May 21, 2009 THx a lot (y) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.