-2

I am returning text results from a PHP FOREACH loop, and I want to add the links add and delete for each result where it looks like this: ADD | DELETE. The trick is, I need each link to be a form that is styled as a link so it looks like text links but I can use Post when the links are clicked. I can style the links with the class name "formlink", but my question is, how will the statement syntax look? I keep getting T_variable errors. Can someone help show how the code below so it will display error-free on the page?

<?php
echo "<hr>" . $results[text]
<form action="" method="post"><button type="submit" class="formlink">Approve</button>
</form>&nbsp;|&nbsp;<form action="" method="post"><button type="submit"
class="formlink">Delete</button></form>
jaw
  • 153
  • 6

2 Answers2

1

That's one messy code though. Well I dunno, I could give you a brief idea, and the rest is up to you.

<?php
// Check clicked button
if (isset($_POST['btn_approve'])) {

    $username = $_POST['username'];
}

if (isset($_POST['btn_disapprove'])) {
    // Do something
}

?>

<form action="" method="post">
    <input type="text" name="username" value="<?php echo (isset($username) ? $username : ''; ?>">
    <input type="submit" name="btn_approve" class="form-link" value="Approve">
    <input type="submit" name="btn_disapprove" class="form-link" value="Disapprove">
</form>

You could check isset() and How to write ternary operator.

Community
  • 1
  • 1
Wesley Brian Lachenal
  • 4,381
  • 9
  • 48
  • 81
0
<?php
    echo "<hr>" . $results[text];
?>
<form action="" method="post">
    <button type="submit" class="formlink">Approve</button>
</form>&nbsp;|&nbsp;
<form action="" method="post">
    <button type="submit" class="formlink">Delete</button>
</form>
Bishal Paudel
  • 1,896
  • 2
  • 21
  • 28