-1

Based on my observations, it appears that when you use the include function to try to use content from another file and then press the submit button, that file is displayed. Here's an example:

I have a file called File1, whose contents are below...

<?php

$submitClicked = false;

if(isset($_POST['submit']))
{
    $submitClicked = true;
}

And now I want to use another file to make output appear on the screen if I click the submit button. I do this with a main file that has html in it:

<!Doctype html>

Practice

<body>
    <form action = "File1.php" method = "POST">

        <?php
            include_once 'File1.php';
            if($submitClicked)
            {
                echo "<h1> <em>Submit Clicked!</em>";
            }

            else
            {
                echo "Nope";
            }
        ?>

        <input type = "submit" name = "submit">
        </input>
    </form>
</body>

Now, when I click the submit button the page literally goes blank. I notice that it's going to the file in the include function. Why does it do that and how do I get it to do what I intend for it to (which is to display Submit Clicked) when the submit button is clicked?

  • 4
    Possible duplicate of [input type="submit" Vs button tag are they interchangeable?](https://stackoverflow.com/questions/7117639/input-type-submit-vs-button-tag-are-they-interchangeable) – Richard Jul 06 '18 at 22:01
  • Using a `button` type does do something. But if you don't put it in a form it won't. – Forbs Jul 06 '18 at 22:08

1 Answers1

0

Button with

<input type="button" />

By default, this does next to nothing. It will not even submit your form. You can only place text on the button and give it a size and a border by means of CSS. Its original (and current) intent was to execute a script without the need to submit the form to the server.

Normal submit button with

<input type="submit" />

Like the former, but actually submits the surrounding form.

So it's easier to use for example in PHP like

if(isset($_POST['submit'])) {

// do xyz calculations

So when a user pushes a button with submit name, it submits the form and we could add data to server, email and do all sorts of things using PHP.

Adnan
  • 21
  • 1
  • 6
  • I disagree. I thought that when it comes to the $_POST superglobal, you have to put the name equal to whatever you are referencing, not the type. Also, this doesn't answer the question of why the submit type goes to a blank page and the button type does not. – n0rmalguy011 Jul 07 '18 at 00:05