简体   繁体   中英

Form submit button isn't working?

I've had this issue before, so I usually always use " <input type='submit' ... > " however I wish to have a bin image as the button as opposed to text (obviously to create a delete button). In order for me to do this I need to use the button tag, however the PHP code isn't working for it.

HTML:

<form action='#' method='POST'>
  <button type='submit' name='form-wallpostdelete'>Delete</button>
</form>

PHP:

$delete_post = @$_POST['form-wallpostdelete']; //Form variable

if($delete_post) {
    echo "Deleted";
}
?>

Really simple, when I use "input type='submit' name='form-wallpostdelete' value='Delete'>" it works, and the message is echoed back, however when I use the button the page simply refreshes.

Use isset() method for checking  
<form action='#' method='POST'>
      <button type='submit' name='form-wallpostdelete'>Delete</button>
    </form>
    <?php 
    $delete_post = @$_POST['form-wallpostdelete']; //Form variable

    if(isset($delete_post)) {
        echo "Deleted";
    }
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM