wolvesbane Posted October 28, 2015 Share Posted October 28, 2015 Hey there, I've been trying to find the cause of the problem but couldn't. needed help from experts out there. the code supposed to echo it's submitted value on the same form when the checkbox is changed. here's the code: <!DOCTYPE html> <?php $office = $_POST["office"]; echo $office; ?> <html> <body> <?php if (isset($office)) { echo "ON<br>"; } else { echo 'OFF<br>'; } ?> <form name="checkbox" method="POST" action="interfaceButton.php" enctype="multipart/form-data"> <?php if(isset($office)){ echo "asdfaf"; echo "<input type='checkbox' name='office' value='on' checked onclick='this.form.submit();'";> } else{ echo '<input type="checkbox" name="office" value="" onClick="submit();"';} ?> </form> </body> </html> Was going to make use this concept and replace the input like a switch button for an web automation project. but im stuck here. Quote Link to comment https://forums.phpfreaks.com/topic/298886-error-need-helpcheckbox-post-form-cant-work/ Share on other sites More sharing options...
wolvesbane Posted October 28, 2015 Author Share Posted October 28, 2015 Hey there, I've been trying to find the cause of the problem but couldn't. needed help from experts out there. the code supposed to echo it's submitted value on the same form when the checkbox is changed. here's the code: <!DOCTYPE html> <?php $office = $_POST["office"]; echo $office; ?> <html> <body> <?php if (isset($office)) { echo "ON<br>"; } else { echo 'OFF<br>'; } ?> <form name="checkbox" method="POST" action="interfaceButton.php" enctype="multipart/form-data"> <?php if(isset($office)){ echo "asdfaf"; echo "<input type='checkbox' name='office' value='on' checked onclick='this.form.submit();'";> } else{ echo '<input type="checkbox" name="office" value="" onClick="submit();"';} ?> </form> </body> </html> Was going to make use this concept and replace the input like a switch button for an web automation project. but im stuck here. output given when code was tried was: "; } else { echo 'OFF'; } ?> } else{ echo '<input type="checkbox" data-cke-saved-name="office" name="office" value="" ';}="" ?=""> Quote Link to comment https://forums.phpfreaks.com/topic/298886-error-need-helpcheckbox-post-form-cant-work/#findComment-1524575 Share on other sites More sharing options...
0x00 Posted October 28, 2015 Share Posted October 28, 2015 Quick glance... Change the following: $office = $_POST["office"]; to if(isset($_POST["office"])){ $office = $_POST["office"]; } The way you currently have it, the variable $office will always be set to something I think... Quote Link to comment https://forums.phpfreaks.com/topic/298886-error-need-helpcheckbox-post-form-cant-work/#findComment-1524577 Share on other sites More sharing options...
Ch0cu3r Posted October 28, 2015 Share Posted October 28, 2015 output given when code was tried was: "; } else { echo 'OFF'; } ?> } else{ echo '<input type="checkbox" data-cke-saved-name="office" name="office" value="" ';}="" ?=""> You should not be seeing the PHP code outputted at all. This suggests to me either the file containing the php code does not have a .php extension or your server is not configured correctly. Can you tell use how you are accessing/running the php code? Quote Link to comment https://forums.phpfreaks.com/topic/298886-error-need-helpcheckbox-post-form-cant-work/#findComment-1524581 Share on other sites More sharing options...
cyberRobot Posted October 29, 2015 Share Posted October 29, 2015 Once the script is being processed as PHP (see Ch0cu3r post above), you should get a parse error for the following line: echo "<input type='checkbox' name='office' value='on' checked onclick='this.form.submit();'";> Note the greater than symbol outside of the quotes. Quote Link to comment https://forums.phpfreaks.com/topic/298886-error-need-helpcheckbox-post-form-cant-work/#findComment-1524693 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.