1

I work as a teacher in adult education and I have developed sites (using Google Sites) for all of our courses at my school. I would like to take our sites a bit further by embedding some HTML elements to them.

One of the things I would like to embed is a feedback form. Since I am new to coding I have been working for a few days trying to get the form to work but I cannot seem to get it to work.

I would really appreciate if you guys could help me figure out what the issue is.

I know it might be very cluttered but this is what I managed to put together using Google Material Design Lite (paste the code here to see it: https://codepen.io/pen/):

<html>
  <head>
    <!-- Material Design Lite -->
    <script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
    <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
    <!-- Material Design icon font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  </head> 
<body>    
  <div class="contact-form">
    <form id="contact-form" method="post" action="#">
      <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
        <input name="name" type="text" class="mdl-textfield__input" id="name">
        <label class="mdl-textfield__label" for="name">Namn (frivligt)</label>
      </div>
      <br>
      <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
        <input name="course" type="text" class="mdl-textfield__input" id="course">
        <label class="mdl-textfield__label" for="course">Kurs (frivligt)</label>
      </div>
      <br>
      <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
        <textarea name="message" class="mdl-textfield__input" rows="7" id="message"></textarea>
        <label class="mdl-textfield__label" for="message">Meddelande</label>
      </div>
      <br>
      <input type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" value="skicka">
    </form>
  </div>
</body>  
</html>

This is the PHP I have written which I have linked with under action="#" by uploading the php file to my github respiratory and linking to it with an URL.

<?php
        if(isset($_POST['Submit'])) {
            $name = $_POST['name'];
            $course = $_POST['course'];
            $message = $_POST['message'];

            $mailTo = "name.lastname@domain.com";
            $headers = "From: Site Form Submission";
            mail($mailTo, $course, $message, $headers);
            header("Location: index.php?mailsend");
        }
?>

When I submit the form on the site a new tab opens in my browser that says 404 Invalid. When I go back to the site the entries in the form are still there. I have never used PHP before so I guess that is where the main issue lies.

Scath
  • 3,777
  • 10
  • 29
  • 40
Feffe
  • 11
  • 1
  • 2
    Are these seperate files? Then you need to put the proper URL into the form action – Nico Haase Apr 25 '18 at 13:27
  • 1
    This `action="#"` references the file where all your form data from the HTML will be posted to. You need to put the name of your php file where you're processing the data to. e.g, if your file is called `contact.php`, the html tag for action would be `action="contact.php"` – Ibrahim Hafiji Apr 25 '18 at 13:30
  • 1
    `if(isset($_POST['Submit'])) {...}else{ echo "Oops! It's not set."; }` you will see the echo here. – Funk Forty Niner Apr 25 '18 at 13:31
  • Also give the input:submit element the name `Submit` as you are checking if it is set in the action file `` – Mihai Matei Apr 25 '18 at 13:31
  • Yes the URL to the php file is put into the form action replacing the ‘#’. It still does not work. – Feffe Apr 25 '18 at 13:35
  • Is your web server configured to execute .php files? Can you reach this PHP script by direct link? – Bushikot Apr 25 '18 at 13:35
  • Did I understand correctly that you are only serving your file from github? You might want to see this thread. Github or github pages don't support php. https://stackoverflow.com/questions/27672315/do-github-pages-support-php – wing Apr 25 '18 at 13:37
  • Well that explains why it isn’t working then. – Feffe Apr 25 '18 at 13:39

0 Answers0