2

I want to send post request using html button. I know it is easily done by jQuery ajax, but i do not want to use jquery and ajax. How can i do it?

This my function

public function editProduct() {
    if($_SERVER['REQUEST_METHOD'] === 'POST') {
        echo 'You are authorized';
    } else {
        echo 'You are not authorized to access this page.';
    }
}

This is my HTML button

<button type="submit" onclick="location.href = '<?=base_url().'company/admin/add_product/editProduct?>';">Send Post Request</button>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Krishna Kumar Yadav
  • 313
  • 1
  • 5
  • 16
  • 1
    you can use
    you can the post data from post.php file
    – Ramki Jun 16 '15 at 09:58
  • Can any option other than form and jquery? – Krishna Kumar Yadav Jun 16 '15 at 10:09
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). BTW, it's "Thanks in advance", not "Thanks in advanced". – John Saunders Jun 17 '15 at 02:29
  • @JohnSaunders Thank u sir. I will remember your suggestion for next time. – Krishna Kumar Yadav Jun 17 '15 at 06:03

2 Answers2

3

In your form tag, just write a method="post"

<form method="post">
 ...
    <button type="submit" >
</form>
Eason.Luo
  • 134
  • 7
1

You have two ways to do this:

  1. via form (best method):

    <form action ="<?php echo base_url().'company/admin/add_product/editProduct'?>" method="post">
          <input type="submit" value="Send Post Request">
    </form>
    
  2. via javascript (jquery: http://api.jquery.com/jquery.post/ )

saurabh kamble
  • 1,510
  • 2
  • 25
  • 42
BaBL86
  • 2,602
  • 1
  • 14
  • 13