Crashtor
Crashtor

Reputation: 1279

PHP form isn't working

Can anyone see what's wrong with these two files? When I click submit, it just redirects me to a blank page and I get no feedback from the form what so ever let alone an email.

HTML code

    <form action="../script/form14.php" method="POST" >

    <h1>KittyBoo</h1>
        <p>Beställ kattmat online - alltid laktos- och glutenfri</p><fieldset class="formular">

    <legend>1. Välj produkt</legend>

        <ul>
            <li>
            <input type="checkbox" name="Kitty Extra Small" value="Kitty Extra Small"> <li> Kitty Extra Small: 90 kr
            <br></li>


            <li>
            <input type="checkbox" name="Kitty Small" value="Kitty Small"> <li> Kitty Small: 140 kr 
            <br></li>

            <li>
            <input type="checkbox" name="Kitty Medium" value="Kitty Medium"> <li> Kitty Medium: 180 kr 
            <br></li>

            <li>
            <input type="checkbox" name="Kitty Large" value="Kitty Large"> <li> Kitty Large: 210 kr 
            <br></li>

            <li>
            <input type="checkbox" name="Kitty Extra Large" value="Kitty Extra Large"> <li> Kitty Extra Large: 240 kr<br></li>
        </ul>
    </fieldset>

<fieldset class="formular">


    <legend>2. Dina uppgifter</legend>

        <label for="namn"> För- och efternamn:</label><br>
            <input type="text" id="namn" name="from" required><br>

        <label for="email">Epost:</label><br>
            <input type="text" id="email" name="email" required><br>

        <label for="emailconfirm">Konfirmera Epost:</label>
            <input type="text" id="emailconfirm" name="emailconfirm" required>

        <label for="adress">Adress:</label>
            <input type="text" id="adress" name="adress" required>

        <label for="postnummer">Postnummer:</label>
            <input type="text" id="postnummer" name="postnummer" required>

        <label for="stad">Stad:</label>
            <input type="text" id="stad" name="stad" required>

        <label for="land">Land:</label>
            <select id="land" name="Land">
                <option> Sverige</option>
                <option> Finland</option>
                <option> Norge</option>
                <option> Danmark</option>
                <option> Island</option>
            </select>

</fieldset>

<fieldset class="formular">


    <legend>3. Leverans</legend>

        <label for="date">Välj datum för leverans:</label>
            <input type="date" id="date" name="date" required/> 

    <p>Leveranssätt:</p>

        <ul>
            <li>
                <input type="radio" name="radAnswer" required value="Posten"> <a> Posten</a>
                <input type="radio" name="radAnswer" required   value="DHL"> <a> DHL</a>
                <input type="radio" name="radAnswer" required  value="FedEx"> <a> FedEx</a>
            </li>
        </ul>

     <p>Välj färg på din KittyBoo:</p>
        <input type="radio"  name="radAnswer" value="bla"> <a> Blå</a>
        <input type="radio"  name="radAnswer" value="rosa"> <a> Rosa</a>

     <p>Övriga önskemål kring din leverans:</p>
        <textarea name="subject" id="ovrig" rows="3" cols="30" maxlength="300" required> Max 300 ord</textarea>

</fieldset>


    <input type="submit" value="skicka">
</form>

PHP Script

<?php

function spamcheck($field)
  {
  // Sanitize e-mail address
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  // Validate e-mail address
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }
?>


<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
  {
  ?>


  <?php 
  }
else
  // the user has submitted the form
  {
  // Check if the "from" input field is filled out
  if (isset($_POST["email"]))
    {
    // Check if "from" email address is valid
    $mailcheck = spamcheck($_POST["email"]);
    if ($mailcheck==FALSE)
      {
      echo "Invalid input";
      }
    else
      {
      $from = $_POST["from"]; // sender
      $subject = $_POST["subject"];
      $email = $_POST["email"]; 




       function build_message($request_input){if(!isset($message_output))
       {$message_output ="";}if(!is_array($request_input))
       {$message_output = $request_input;}
       else{foreach($request_input as $key => $value)
       {if(!empty($value)){if(!is_numeric($key))
       {$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}
       else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

    $message = build_message($_REQUEST);


      // message lines should not exceed 70 characters (PHP rule), so wrap it
      $message = wordwrap($message, 70);
      // send mail
      mail("[email protected]",$subject,$message, "From: $from\n");
      echo "Tillbakaack f&ouml;r ditt meddelande";
        echo "<p><a href=http://www.sh.se>Tillbaka till sidan</a></p>";
      }
    }
  }
?>

The server is set up for PHP.

If it would be of any help, you can check the form out here:http://student.mtstudent.se/~sh14hf2407/pages/formular.html

Upvotes: 0

Views: 56

Answers (2)

user4486345
user4486345

Reputation:

change

<input type="submit" value="skicka"> 

into

<input type="submit" name="submit" value="skicka">

Upvotes: 0

St&#233;phane
St&#233;phane

Reputation: 116

Your PHP condition if (!isset($_POST["submit"])) { ... } is always FALSE because $_POST['submit'] doesn't exist in your html form. You have created an element <input type="submit" value="skicka"> but $_POST['submit'] means "an element which name attribute is submit". So replace :

<input type="submit" value="skicka">

by

<input type="submit" name="submit" value="skicka">

and this issue will be fixed.

Upvotes: 1

Related Questions