edemco Posted April 27, 2011 Share Posted April 27, 2011 Hello, :'( I didn't want to learn php; wish I could find a wysiwyg program to do basic coding ... so you know that I'm a noob. I have a php file that I've been working on. Most of the code was written by other people. I'm trying to add a checkbox that requires the user to agree to the terms of membership. The form works (for all other form entries) and it updates the database with "yes" in the field "agree" for the checkbox. What it doesn't do is verify that the checkbox is marked and prevent the user from continuing. At this time, the form updates regardles of the checkbox being marked or not. I have run out of hunches and need some expert eyes, please? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/ Share on other sites More sharing options...
cssfreakie Posted April 27, 2011 Share Posted April 27, 2011 well, not willing to learn or showing effort means your topic belongs in the freelance forum. for now this could be something to have a look in, but please if your not willing to put time in it yourself, post this in the freelance forum. //simple check if the value is as you want by using an if-clause if($_POST['agreecheck'] == 'yes'){ //so if the post value is equal to 'yes' //perform an action; echo 'value is yes'; }else{ //if value is not equal to yes, do something echo 'value is not yes, you need to agree blabla bla'; } more info here: http://www.tizag.com/phpT/ifelse.php if you do all examples there you should know what to do, if not post the code here in code tags and show what you tried. Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207244 Share on other sites More sharing options...
edemco Posted April 27, 2011 Author Share Posted April 27, 2011 I guess I need to watch my levity ... it doesn't come through print very well :-\ Truthfully, I've spent a week of days working on this page and several others. I'm learning, but it takes time to absorb the learing through the fingers in into the brain These pages generally work as expected. The foundation work was paid for. If I need to get it done in a short time, I am not above paying for it to be done. But I need to learn, so I'm paying my dues by the minute. Here's what I understand: 1. Since, I am checking the contents of a checkbox in a form, with a submit button, I need to have php coding of the following form: // Checking the Checkbox if (isset ($_POST['agree'])) { if (!isset($_POST['agree'])){ header("Location:memberAppMishe1.php"); echo "You need to agree to the terms of membership. "; // redirect them back as they didn't check the box } else { // continue... they checked the box } } 2. The checkbox is called for in the HTML code and currently functions to post "yes" to the databased field "agree." The code is: I agree to the terms of membership. <input type="checkbox" name="agree" value="Yes"> 3. The php code should check to see if "agree" is filled or blank; (isset ($_POST['agree'])) should see null if the checkbox is not marked and should pass to (!isset ($_POST['agree'])) where it should ECHO: "You need to agree ... All of this is in the attached file, but I know that it is hard to read. I hope this helps. I have a hunch that I am not putting something in the right place or misinterpreting the code. Any assistance would be appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207276 Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 Okay have a look at the code below. The code below assumes that ones someone presses agree the value is 'yes' Hope this makes it more clear. <?php // Checking the Checkbox if (isset ($_POST['agree']) && $_POST['agree'] == 'yes') { //so if $_POST['agree'] is set and has a value of yes echo "congrats the value of \$_POST['agree'] = yes"; echo $_POST['agree']; }else{ //so in any other case header("Location:memberAppMishe1.php"); // you need to agree bla bla bla exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207306 Share on other sites More sharing options...
edemco Posted April 28, 2011 Author Share Posted April 28, 2011 At first glance this looks good, but there must be some interference with the other code in the file, because I get a page redirect error. The code seems to get caught in a loop. The funny thing is that my code doesn't do that. I see the value of using && and doing an absolute check for "yes", but if "yes" isn't there, it should send the same page image back to the screen with an echo statement in place of the bla bla that says "you must agree." But, the problem still exists - it should stop if the checkbox is not marked. <?php // Checking the Checkbox if (isset ($_POST['agree']) && $_POST['agree'] == 'yes') { //so if $_POST['agree'] is set and has a value of yes echo "congrats the value of \$_POST['agree'] = yes"; echo $_POST['agree']; }else{ //so in any other case header("Location:memberAppMishe1.php"); // you need to agree bla bla bla exit; } ?> Instead, should the code be something like: <?php // Checking the Checkbox if (isset ($_POST['agree']) && $_POST['agree'] == ' ') { //so in this case header("Location:memberAppMishe1.php"); echo "You need to agree to the terms." }else{ //But what happens here?? I don't think anything should happen, right? } ?> This logic doesn't work either. I must be completely wrong. Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207347 Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 uhm <input type="checkbox" name="agree" value="Yes"> is your html so the value is not yes but Yes. That's why I said this assume the value is yes. because i wasn't very eager to download the file so i hoped you spotted that yourself. So give the code i already gave a value of Yes instead of yes and than it should work fine. like: <?php // Checking the Checkbox if (isset ($_POST['agree']) && $_POST['agree'] == 'Yes') { // changed yes into Yes //so if $_POST['agree'] is set and has a value of Yes echo "congrats the value of \$_POST['agree'] = Yes"; echo $_POST['agree']; }else{ //so in any other case header("Location:memberAppMishe1.php"); // you need to agree bla bla bla exit; //remove this exit if the header redirect is incorrect in this ELSE statement } ?> also note that i placed that header redirect in the else statement, if that is meant for the case someone did fil in agree with Yes place that code after the if clause. like so: <?php // Checking the Checkbox if (isset ($_POST['agree']) && $_POST['agree'] == 'Yes') { // changed yes into Yes //so if $_POST['agree'] is set and has a value of Yes header("Location:memberAppMishe1.php"); exit; }else{ //so in any other case // you can't echo something here since it's above your <body> but you can set a value to show up. like: $errormessage = 'you need to agree bla bla bla'; // and echo this variable inside your body tag. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207442 Share on other sites More sharing options...
edemco Posted April 28, 2011 Author Share Posted April 28, 2011 Unfortunately, when I paste the code you provided into the rest of the code, I get a redirect error. When I remove the "header" line, program exits with a blank screen. I can change the "location" and refreshing the page makes it go to another "location". Without a "Yes", the page loops. (BTW: I changed the case to match in a prior rendition of the code, but thanks for point it out again.) There is more posting and updating that needs to be done after the "exit" in your code - I need to go past the code to complet the update sequence if there is a "Yes" in the checkbox. I'm trying to get the program to stop posting operations until the "required" checkbox is marked and not to post until verifying that the checkbox is marked. In this way the user is warned and continually refused until the checkbox is marked "Yes." Nothing should go to the database (as it is now). (BTW: I can get this code and other similar code to work outside of the rest of the code. I have a hunch that the code we are talking about is either not in the right place or does not interface well with the other code.) In my way of thinking, the code should stop the action with the first part of the "if" statement and allow continuance with "else." How can the database updating be stopped until the checkbox is marked? Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1207619 Share on other sites More sharing options...
edemco Posted April 29, 2011 Author Share Posted April 29, 2011 I continue to work with the code, but I have not found a solution that works. Do you have any further thoughts or suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/234905-checkbox-verification-to-allow-or-renew-registration/#findComment-1208319 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.