0

I want to be able to carry $_POST['v'] (string) to delete.php using an HTML form button.

$directory = "exports/";
$contents = scandir($directory,1);
foreach($contents as $k => $v) {
if ($v != '.' && $v != '..') { 
  echo "<a href=\"$directory" . $v . "\">".$v."</a>";
  echo "<form action=\"delete.php\" method=\"post\"><a class=\"buttonnohover\"><input type=\"submit\" class=\"button\" name=\"v\" value=\"Delete\" /></form>  <br>";
  }
}

At the moment the submit button simply brings back string(6) "Delete". I want $_POST['v'] to equal each individual $v (filename within the directory) carried on each button.

What am I not doing right?

2
  • 3
    And what is your question? Commented Jan 8, 2014 at 23:03
  • I think you want the submit button to have a value, is that correct? Commented Jan 8, 2014 at 23:04

1 Answer 1

2

When you want to get the value of $v to delete.php using the form, you can use a hidden input:

echo '<a href="'.$directory.$v.'">'.$v.'</a>';
echo '<form action="delete.php method="post">
    <input type="hidden" name="v" value="'.$v.'" />
    <a class="buttonnohover"><input type="submit" class="button" name="submit" value="Delete" />
    </form><br>';

Currently you are getting "Delete" back, because it is the value of the button - just as you defined it in the HTML.

Additionally I would suggest renaming $v to $filename - currently it is only a cryptic variable, because the context is small of course you know what it holds, but only by looking at other lines of code. When you name it $filename, you'll directly know what the content of that variable will be.

Sign up to request clarification or add additional context in comments.

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.