0

I am running Apache on a MAC with

$ apachectl start

The index.html is at /Library/WebServer/Documents

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>blah</title>
</head>

<body>
  <p>test html file: hello world</p>
  <button type="button" name="button" action="contact.php">Press me</button>

</body>

</html>

That page displays in the browser at port 80.

It should call a contact.php file when the button is pressed and this simple echoes a string. But where should I be able to see this string and so be able to check that contact.php is being called and running as expected?

contact.php

<?php

echo "blah1234567890";

?>

Thanks,

Shane G
  • 3,129
  • 10
  • 43
  • 85
  • Yes this is a duplicate, but I didn't realise the problem was that I was using the button as a link and should have been using the form and input tags. Thanks – Shane G May 18 '18 at 20:06

2 Answers2

1

you can use :

<form action="contact.php">
    <input type="submit" value="Press me">
</form>

instead of :

<button type="button" name="button" action="contact.php">Press me</button>

in your index.html file.

With the formaction attribute you can specify multiple submit URLs for one form. Because the action attribute is no longer required for the form element you could define the submit URL(s) just in the formaction of a submit button. When the form is submitted, the browser first checks for a formaction attribute; if that isn’t present, it proceeds to look for an action attribute on the form element.

Alihossein shahabi
  • 4,034
  • 2
  • 33
  • 53
1

action is not a valid attribute of the button element in html5.

Here is one option to make the button act like a link (if that's what you're trying to achieve) using the onclick attribute:

<button type="button" name="button" onclick="window.location.href='contact.php';">Press me</button>
Nick Rolando
  • 25,879
  • 13
  • 79
  • 119