1

enter image description hereI have a form with three buttons.. one button is to edit form in another page, second one is to add value on existing page, third one its to delete value.. submit and edit works well.. now i need to work on delete button.. as it is a button.. i am unable to get value with $_POST or $_GET and $_REQUEST i have done something like this..

<form method="POST">
  <input type="text" name="example_text" />

  <a href="index.php?del">
    <input type="button" value="Delete" />
  </a>
  <!-- works fine !-->
  <a href="someotherpage.php">
  <input type="button" value="edit" />
    </a>
  <!-- works fine !-->
  <input type="submit" name="submit" />
  </form>

<?php 
if(isset($_POST['submit']))
{
echo "submit can get value by $_POST";
$name = $_POST['example_text'];
}
if(isset($_GET['del']))
{
$name = $_REQUEST['example_text']; // this can't get value;
$name = $_POST['example_text'];  // this can't get value;
$name = $_GET['example_text']; // this can't get value;
}
?>
2
  • can i use two submits? in one form? Commented Dec 3, 2014 at 7:22
  • 1
    Yes you can, see my answer. Commented Dec 3, 2014 at 7:33

4 Answers 4

2

replace

<a href="index.php?del">
    <input type="button" value="Delete" />
  </a>

to

<input type="submit" value="Delete" name="del"/>

give your each button a name so you can check which button has been submitted

for check delete button clicked

if(isset($_POST['del'])) {
}
Sign up to request clarification or add additional context in comments.

1 Comment

you can set multiple submit by using name different like name="del"
1

Try this it will work fine :

<html>
<head>
<script>
function button1()
{
var r=  document.getElementById('example_text').value;

window.location="getdetails.php?data="+r;
}
function button2()
{
var r=  document.getElementById('example_text').value;

window.location="getdetails.php?data="+r;
}
</script>
</head>
<body>
<form method="POST">
  <input type="text" name="example_text" id="example_text"/>

  <a href="index.php?del">
    <input type="button" value="Delete" onclick="button1()"/>
  </a>
  <!-- works fine !-->
  <a href="someotherpage.php">
  <input type="button" value="edit" onclick="button1()"/>
    </a>
  <!-- works fine !-->
  <input type="submit" name="submit" />
  </form> 
</body>
</html>

1 Comment

nice share.. but i was looking for php
0

Try this:

<form method="POST">
  <input type="text" name="example_text" />

  <input type="submit" name="delete" value="Delete" />

  <a href="someotherpage.php">
    <input type="button" name="edit" value="Edit" />
  </a>

  <input type="submit" name="submit" value="Submit" />
</form>

<?php

    if(isset($_REQUEST['submit']))
    {
        $name = $_REQUEST['example_text'];
        echo "Submit method: ".$name;
    }

    if(isset($_REQUEST['delete']))
    {
        $name = $_REQUEST['example_text'];
        echo "Delete method: ".$name;
    }

?>

Comments

0

Typo:

Change

$name = $_REQUESR['example_text']; // this can't get value;

To:

$name = $_REQUEST['example_text']; // this can't get value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.