Jump to content

Recommended Posts

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.
 

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="" ';}="" ?="">

 

 

 

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...

 

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.