HTML Formu gönderdikten sonra PHP Hataları Önleme

0 Cevap php

Ben PHP ile bir e-posta gönderen bir HTML formu inşa ettik, ama bana böyle bakmak bazı hatalar veriyor:

Uyarı: Undefined variable: 8. satırda / webdocs/com-interplay2010-www-1i/webroot/holiday2010/submit.php içinde selected_radio

Notice: Undefined index: 12 hattı üzerinde / webdocs/com-interplay2010-www-1i/webroot/holiday2010/submit.php toplumsal cinsiyet

Meydana gelen bu hataları önlemek bir yol olsaydı benim kod temiz görünüyor bu yana, merak ediyordum.

Burada HTML formu kodu:

<form id="registerform" action="submit.php" method="post">
        <div class="shoeType">
          <input type="radio" name="type" id="olive" value="Olive" />
          <label for="olive">Olive</label>
          <input type="radio" name="type" id="red" value="Red" />
          <label for="red">Red</label>
          <input type="radio" name="type" id="ash" value="Ash" />
          <label for="ash">Ash</label>
          <input type="radio" name="type" id="custom" value="Custom" />
          <label for="custom">Custom</label>
          <input type="radio" name="type" id="donate" value="Donate" />
          <label for="donate">Donate</label>
        </div>

        <div class="genderSize">
            <p class="gender">Gender
              <label for="male" class="m">Male</label>
              <input type="radio" name="gender" id="male" value="male" />
              <label for="female" class="f">Female</label>
              <input type="radio" name="gender" id="female" value="female" />
            </p>
            <p class="size male">
              <select id="sizeMale" name="sizeMale">
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="8.5">8.5</option>
                <option value="9">9</option>
                <option value="9.5">9.5</option>
                <option value="10">10</option>
                <option value="10.5">10.5</option>
                <option value="11">11</option>
                <option value="11.5">11.5</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="13">14</option>
              </select>
            </p>
            <p class="size female">
              <select id="sizeFemale" name="sizeFemale">
                <option value="6">6</option>
                <option value="6.5">6.5</option>
                <option value="7">7</option>
                <option value="7.5">7.5</option>
                <option value="8">8</option>
                <option value="8.5">8.5</option>
                <option value="9">9</option>
                <option value="9.5">9.5</option>
                <option value="10">10</option>
                <option value="11">11</option>
              </select>
            </p>
        <div class="clear"></div>  
        </div>

        <div class="favColor">
            <p>
          <label for="favColor">Favorite Color</label>
          <input type="text" id="favColor" name="favColor" size="20" />
            </p>
        </div>

        <div class="personalInfo">
            <p>
              <label for="name">Name</label>
              <input type="text" id="name" name="name" />
            </p>
            <p>
              <label for="company">Company</label>
              <input type="text" id="company" name="company"/>
            </p>
            <p>
              <label for="address">Address</label>
              <textarea id="address" name="address"></textarea>
            </p>

            <p class="agree">
              <input type="checkbox" id="agree" name="agree" class="clear" />
              <label for="agree">By checking this box, you give us permission to list your name and company as a donor on our “Agency with Sole” website</label>
            <p class="clear"></p>        
        </p>    
        </div>
        <!--<input type="submit" value="SUBMIT" class="submit" />-->
        <input type="submit" value="SUBMIT" class="submit" />
        <div class="clear"></div>
      </form>

ve burada benim PHP kodu:

<?php
// get posted data into local variables
$EmailFrom = "LEVEL Studios Holiday 2010"; 
$EmailTo = "rpessagno@level-studios.com";
$Subject = "TOMS Shoes Order";

$type = trim(stripslashes($_POST['type']));
print $selected_radio;
$name = trim(stripslashes($_POST['name']));
$company = trim(stripslashes($_POST['company']));
$address = trim(stripslashes($_POST['address']));
$gender = trim(stripslashes($_POST['gender'])); 
print $selected_radio;
$sizeMale = trim(stripslashes($_POST['sizeMale']));
$sizeFemale = trim(stripslashes($_POST['sizeFemale']));
$age = trim(stripslashes($_POST['age']));
$favColor = trim(stripslashes($_POST['favColor']));
$agree = trim(stripslashes($_POST['agree']));

// validation
$validationOK = true;
if (trim($EmailFrom)=="") {
    $validationOK = false;
}
if (!$validationOK) {
  print "";
  exit;
}

// prepare email body text
$Body = "Hi Valerie, \n\nSomebody would like to put in a TOMS Shoes order \n\n";

$Body .= "Shoe Type? \n";
$Body .= $type;
$Body .= "\n\n";

$Body .= "Name \n";
$Body .= $name;
$Body .= "\n\n";

$Body .= "Company \n";
$Body .= $company;
$Body .= "\n\n";

$Body .= "Mailing Address \n";
$Body .= $address;
$Body .= "\n\n";

$Body .= "Gender \n";
$Body .= $gender;
$Body .= "\n\n";

$Body .= "Size \n";
$Body .= $sizeMale;
$Body .= "\n\n";

$Body .= "Size \n";
$Body .= $sizeFemale;
$Body .= "\n\n";

$Body .= "Age \n";
$Body .= $age;
$Body .= "\n\n";

$Body .= "Favorite Color \n";
$Body .= $favColor;
$Body .= "\n\n";

$Body .= "Agree \n";
$Body .= $agree;
$Body .= "\n\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<div id='result'>OK</div>";
} else {
  print "<div id='result'>ERROR</div>";
}
?>

0 Cevap