tags:

views:

142

answers:

5
+1  Q: 

Simple PHP problem

<?php if (isset($_GET['action']) && (!$_GET['action'] == 'reply')) { ?>
<div class="actions">
<input type="button" onclick="javascript: document.location='?threadID=<?=$threadID?>&action=reply';" value="Post reply" class="btn" />
</div>
<?php } ?>

What i wanna achive with this is to hide this when im callin reply. doesnt show at all.

Can you see the problem?

cheers

+2  A: 
if (isset($_GET['action']) && ($_GET['action'] == 'reply'))

or

if (isset($_GET['action']) && ($_GET['action'] != 'reply'))

Not sure what you're trying to do with !$_GET['action'] == 'reply'

rpflo
+4  A: 

try
if (isset($_GET['action']) && $_GET['action'] !== 'reply') {

chendral
A: 

What about something like this? I think using "POST" is more elegant and has more options for further development than passing them via "GET":

<?php if(!isset($_POST['action'])){ ?>
  <form method="post">
    <input type="hidden" name="threadID" value="<? echo $threadID; ?>" />
    <input type="button" name="action" value="Post reply" class="btn" />
  </form>
<?php } ?>

Just a small additional note: You probably want to check if threadID is valid or not and THAN decide whether to show the form or not.

merkuro
+2  A: 

You should do better like this:

<div class="actions">
<?php 
if (isset($_GET['action']) && ($_GET['action'] != 'reply')) 
{ 
    echo '<input type="button" onclick="javascript: document.location='?threadID=<?=$threadID?>&action=reply';" value="Post reply" class="btn" />';
} 
?>
</div>

This way you can add further actions when you can reply.

Timotei Dolean
A: 

I suspect that the first time you hit this page, there's no action parameter in the URL. If so, then isset() is going to be false. Also, you probably want !=, rather than ! ... == ....

I haven't tested this code, but here's where I would start:

<?php if (!isset($_GET['action']) || ($_GET['action'] != 'reply')) { ?>
    <div class="actions">
    <input type="button" onclick="javascript: document.location='?threadID=<?=$threadID?>&action=reply';" value="Post reply" class="btn" />
    </div>
<?php } ?>

I also find this format slightly easier to read:

<?php if (!isset($_GET['action']) || ($_GET['action'] != 'reply')): ?>
    <div class="actions">
    <input type="button" onclick="javascript: document.location='?threadID=<?=$threadID?>&action=reply';" value="Post reply" class="btn" />
    </div>
<?php endif; ?>
Don Kirkby
thank you very much!