2015-04-02 6 views
-1

Моя форма работала до и теперь, когда я добавил всплывающее окно подтверждения внизу, оно больше не работает. Я не знаю, что происходит, и я надеюсь, что второй взгляд на это покажет мою ошибку. Заранее благодарю за это!Форма и валидация PHP не работают

<?php #Registration 

//Arrays 
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); 
$season = array('Fall 2014', 'Winter 2014', 'Spring 2015', 'Summer 2015'); 
$days = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'); 
$locations = array('Priest River', 'Sandpoint', 'Online'); 

function makeSafe($value) { 
    return stripslashes(trim($value)); 
} 

//Form Subitted 
if (!empty($_POST['submit'])) { 
    //form submitted through post, do validation 

    $authorization = (!empty($_POST['authorization'])) ? makeSafe($_POST['authorization']) : ''; 
    $signature = (!empty($_POST['signature'])) ? makeSafe($_POST['signature']) : '';  
    $cc = makeSafe($_POST['cc']); 
    $ll = makeSafe($_POST['ll']); 
    $fname = makeSafe($_POST['fname']); 
    $mname = makeSafe($_POST['mname']); 
    $lname = makeSafe($_POST['lname']); 
    $pname = makeSafe($_POST['pname']); 
    $mm = makeSafe($_POST['mm']); 
    $dd = makeSafe($_POST['dd']); 
    $year = makeSafe($_POST['year']); 
    $age = makeSafe($_POST['age']); 
    $school = makeSafe($_POST['school']); 
    $address = makeSafe($_POST['address']); 
    $city = makeSafe($_POST['city']); 
    $state = makeSafe($_POST['state']); 
    $zip = makeSafe($_POST['zip']); 
    $gender = makeSafe($_POST['gender']); 
    $email = makeSafe($_POST['email']); 
    $phone = makeSafe($_POST['phone']); 
    $altph = makeSafe($_POST['altph']); 
    $sn = makeSafe($_POST['sn']); 
    $hp = makeSafe($_POST['hp']); 
    $packet = (!empty($_POST['signature'])) ? makeSafe($_POST['packet']) : ''; 
    $message = ''; 
    $problem = FALSE; 

    //Check Season Selected DropDown Array 
    if(isset($_POST['cc']) && !empty($_POST['cc'])) 
    { 
     // if cc is in $season array 
     if(in_array($_POST['cc'], $season)) 
     { 
      // this value is not accepted or "- Select Season -" selected 
     } 
     else 
     { 
      $seasonMessage .= '<p class="errorClass">Required</p>'; 
     } 
    } 

    //Check Class Location Selected DropDown Array 
    if(isset($_POST['ll']) && !empty($_POST['ll'])) 
    { 
     // if ll is in $locations array 
     if(in_array($_POST['ll'], $locations)) 
     { 
      // this value is not accepted or "- Select Location -" selected 
     } 
     else 
     { 
      $locationMessage .= '<p class="errorClass">Required</p>'; 
     } 
    } 

    //Check Birth Month Selected DropDown Array 
    if(isset($_POST['mm']) && !empty($_POST['mm'])) 
    { 
     // if mm is in $months array 
     if(in_array($_POST['mm'], $months)) 
     { 
      // this value is not accepted or "- Select Month -" selected 
     } 
     else 
     { 
      $monthMessage .= '<p class="errorClass">Required</p>'; 
     } 
    } 

    //Check Birth Day Selected DropDown Array 
    if(isset($_POST['dd']) && !empty($_POST['dd'])) 
    { 
     // if dd is in $day array 
     if(in_array($_POST['dd'], $days)) 
     { 
      // this value is not accepted or "- Select Day -" selected 
     } 
     else 
     { 
      $dayMessage .= '<p class="errorClass">Required</p>'; 
     } 
    } 

    //Check Gender 
    //if (empty($_POST["gender"])) { 
     //$genderMessage .= '<p class="errorClass">Required</p>'; 
    //} 

    //Check Read Authorization 
    if($_POST['authorizaton']!="1" AND $_POST['packet']!="1"){ 
     $problem = TRUE; 
     $parentMessage .= '<p class="errorClass parentMsg">Please read and check the boxes below.</p>'; 
    } 

    //Check Electronic Signature 
    if($_POST['signature']!="1"){ 
     $problem = TRUE; 
     $signatureMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check First Name 
    if (!eregi ('^[[:alpha:]\.\' \-]{2,}$',$fname)) { 
     $problem = TRUE; 
     $fnameMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Last Name 
    if (!eregi ('^[[:alpha:]\.\' \-]{2,}$',$lname)) { 
     $problem = TRUE; 
     $lnameMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Parent/Guardian Name 
    if (!eregi ('^[[:alpha:]\.\' \-\ ]{2,}$',$pname)) { 
     $problem = TRUE; 
     $pnameMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check School Name 
    if (!eregi ('^[[:alnum:]\.\' \-\,]{4,}$', $school)) { 
     $problem = TRUE; 
     $schoolMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Student Address 
    if (!eregi ('^[[:alnum:]\.\' \#\-]{4,}$', $address)) { 
     $problem = TRUE; 
     $addyMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check City 
    if (!eregi ('^[[:alpha:]\.\' \-]{4,}$', $city)) { 
     $problem = TRUE; 
     $cityMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check State 
    if (!eregi ('^[[:alpha:]\.\' \-\ ]{2,2}$', $state)) { 
     $problem = TRUE; 
     $stateMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Email 
    if (!eregi ('^[[:alnum:]][a-zA-Z0-9._-][email protected][a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$email)) { 
     $problem = TRUE; 
     $emailMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Zip 
    if (!eregi ('^[0-9]{5}(\-[0-9]{4})?$',$zip)) { 
     $problem = TRUE; 
     $zipMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Phone 
    if (!eregi ('^[0-9.\(\)\-\ ]{10,14}$', $phone)) { 
     $problem = TRUE; 
     $phoneMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Age 
    if(!eregi('^[0-9]{2}$',$age)) { 
     $problem = TRUE; 
     $ageMessage .= '<p class="errorClass">Required</p>'; 
    } 

    //Check Year 
    if(!eregi('^[0-9]{2,4}$',$year)) { 
     $problem = TRUE; 
     $yearMessage .= '<p class="errorClass">Required</p>'; 
    } 

    if ($problem == TRUE) {//Something went wrong 
     echo $message; 
     echo '';   
    } 
    else{ 
     $to = "[email protected]"; 
     $subject = "Buckle-Up New Student Registration for $fname $lname"; 
     $headers = 'From: [email protected]' . "\r\n" .'X-Mailer: PHP/' . phpversion(); 

     $msg .= "PLAIN TEXT EMAIL\n\n"; 
     $msg .= "Location: $ll  Class: $cc\n\n"; 
     $msg .= "Name: $fname $mname $lname\n\n"; 
     $msg .= "Parent/Guardian Name: $pname\n\n"; 
     $msg .= "Birthday: $mm $day $year  Age: $age  Gender: $gender\n\n"; 
     $msg .= "School: $school\n\n"; 
     $msg .= "Address: $address\n\n"; 
     $msg .= "City: $city  State: $state  Zip Code: $zip\n\n"; 
     $msg .= "Phone: $phone  Alternate Contact: $altph\n\n"; 
     $msg .= "Email: $email\n\n"; 
     $msg .= "Special Needs: $sn\n\n"; 
     $msg .= "Health Problems or Allergies: $hp\n\n"; 
     $msg .= "I Parent/Guardian understand the traffic safety education course consists of 30 clock-hours of classroom instruction, 6 hours of behind-the-wheel instruction and 6 hours of in-car observation. I also understand that instruction is provided by a properly certified instructor licensed by the Idaho Department of Education and the Idaho Bureau of Occupational Licenses, and the behind-the-wheel training takes place in a dual-control vehicle that is adequately insured. I accept the fact that the Buckle-UP Driving School, LLC will not be responsible for any driving the student may do outside the Driver Education program. In addition I acknowledge that portions of the student participation in this traffic safety education course may be videotaped for feedback and grading as well as for use in future training courses.\n\n"; 
     $msg .= "I Parent/Guardian have read the student/parent or guardian information packet for Driver Education and hereby give approval for the above student to participate in the course.\n\n"; 
     $msg .= "Parent/Guardian Authorized Signature: Electronically Signed\n\n"; 

     if(mail($to, $subject, $msg, $headers) == false){ 
      // Email failed 
      echo "<script type='text/javascript'>alert('failed!')</script>"; 
     } 
     else { 
      echo 
      $authorization = ''; 
      $ll = ''; 
      $cc = ''; 
      $fname = ''; 
      $mname = ''; 
      $lname = ''; 
      $pname = ''; 
      $mm = ''; 
      $dd = ''; 
      $year = ''; 
      $age = ''; 
      $school = ''; 
      $address = ''; 
      $city = ''; 
      $state = ''; 
      $zip = ''; 
      $gender = ''; 
      $email = ''; 
      $phone = ''; 
      $altph = ''; 
      $hp = ''; 
      $sn = ''; 
      $signature = ''; 
      $packet = ''; 
     } 
    } 
} 
?> 

HTML

<form id="registration" class="registrationSettings" name="registration" method="post" action="#" onsubmit="myFunction();return false")> 
<div class="formHeading">DRIVER EDUCATION ENROLLMENT FORM</div> 
<section>  
<div class="fieldBox"> 
    <div class="label"><p class="bold">Location</p></div> 
    <div class="field"><?php echo $locationMessage; ?> 
    <select name="ll" class="select-form-style"> 
     <option>- Select Location -</option> 
     <?php 
      foreach ($locations as $location) { 
      $selected = (!empty($ll) && $ll == $location) ? 'selected="selected"' : ''; 
     ?> 
     <option value="<?php echo $location;?>" <?php echo $selected;?>><?php echo $location;?></option> 
     <?php 
      } 
     ?> 
    </select> 
    </div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Schedule</p></div> 
    <div class="field"><?php echo $seasonMessage; ?> 
    <select name="cc" class="select-form-style"> 
     <option>- Select Schedule -</option> 
     <?php 
      foreach ($season as $season) { 
      $selected = (!empty($cc) && $cc == $season) ? 'selected="selected"' : ''; 
     ?> 
     <option value="<?php echo $season;?>" <?php echo $selected;?>><?php echo $season;?></option> 
     <?php 
      } 
     ?> 
    </select> 
    </div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">First Name</p></div> 
    <div class="field"><?php echo $fnameMessage; ?> 
<input type="text" title="First Name" name="fname" value="<?php echo $fname; ?>" 
maxlength="32" class="fnameField" autocomplete="on" /> 
</div>    
</div> 

<div class="fieldBox"> 
    <div class="label"><p>Middle</p></div> 
    <div class="field"> 
<input type="text" title="Middle Name" name="mname" value="<?php echo $mname; ?>" 
maxlength="20" class="mnameField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Last Name</p></div> 
    <div class="field"><?php echo $lnameMessage; ?> 
<input type="text" title="Last Name" name="lname" value="<?php echo $lname; ?>" 
maxlength="32" class="lnameField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Parent/Guardian Name</p></div> 
    <div class="field"><?php echo $pnameMessage; ?> 
<input type="text" title="Parent Name" name="pname" value="<?php echo $pname; ?>" 
maxlength="32" class="pnameField" autocomplete="on" /> 
</div>    
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Birthday</p></div> 
    <div class="field"><?php echo $monthMessage; ?> 
<select name="mm" class="select-form-style"> 
<option> 
- Select Month - 
</option> 
<?php 
foreach ($months as $month) { 
$selected = (!empty($mm) && $mm == $month) ? 'selected="selected"' : ''; 
?> 
<option value="<?php echo $month;?>" <?php echo $selected;?>> 
<?php echo $month;?> 
</option> 
<?php 
} 
?> 
</select> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Day</p></div> 
    <div class="field"><?php echo $dayMessage; ?> 
    <select name="dd" class="select-form-style"> 
     <option>- Select Day -</option> 
     <?php 
      foreach ($days as $day) { 
      $selected = (!empty($dd) && $dd == $day) ? 'selected="selected"' : ''; 
     ?> 
     <option value="<?php echo $day;?>" <?php echo $selected;?>><?php echo $day;?></option> 
     <?php 
      } 
     ?> 
    </select> 
    </div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Year</p></div> 
    <div class="field"><?php echo $yearMessage; ?> 
<input type="text" title="Year" name="year" value="<?php echo $year; ?>" 
maxlength="4" class="byearField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Age</p></div> 
    <div class="field"><?php echo $ageMessage; ?> 
<input type="text" title="Age" name="age" value="<?php echo $age; ?>" 
maxlength="2" class="ageField" autocomplete="on" /> 
</div> 
</div> 

<div class="radioFieldBox"> 
    <div class="label"><p class="bold">Gender</p></div> 
    <div class="field"> 
    <div class="radioGroup"> 
<input type="radio" id="genderSelectMale" class="" name="gender" value="Male" /> 
<label for="genderSelectMale"><span></span>Male</label> 
<input type="radio" id="genderSelectFemale" class="" name="gender" value="Female" /> 
<label for="genderSelectFemale"><span></span>Female</label> 
</div> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">School</p></div> 
    <div class="field"><?php echo $schoolMessage; ?> 
<input type="text" title="School" name="school" value="<?php echo $school; ?>" 
maxlength="30" class="schoolField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Home Address</p></div> 
    <div class="field"><?php echo $addyMessage; ?> 
<input type="text" title="Street Address" name="address" value="<?php echo $address; ?>" 
maxlength="30" class="addyField" autocomplete="on" /> 
</div> 
</div>  

<div class="fieldBox"> 
    <div class="label"><p class="bold">City</p></div> 
    <div class="field"><?php echo $cityMessage; ?> 
<input type="text" title="City" name="city" value="<?php echo $city; ?>" 
class="cityField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">State</p></div> 
    <div class="field"><?php echo $cityMessage; ?> 
<input type="text" title="State" name="state" value="<?php echo $state; ?>" 
maxlength="2" class="stateField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Zip</p></div> 
    <div class="field"><?php echo $zipMessage; ?> 
<input type="text" title="Zip Code" name="zip" value="<?php echo $zip; ?>" 
maxlength="9" class="zipField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Phone</p></div> 
    <div class="field"><?php echo $phoneMessage; ?> 
<input type="text" title="Phone Number" name="phone" value="<?php echo $phone; ?>" 
maxlength="14" class="phoneField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p>Alternate Phone</p></div> 
    <div class="field"> 
<input type="text" title="Alternate Phone Number" name="altph" value="<?php echo $altph; ?>" 
maxlength="14" class="altPhoneField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p class="bold">Email</p></div> 
    <div class="field"><?php echo $emailMessage; ?> 
<input type="text" title="Email Address" name="email" value='<?php echo $email; ?>' 
maxlength="30" class="emailField" autocomplete="on" /> 
</div> 
</div> 

<div class="fieldBox"> 
    <div class="label"><p>Special Needs</p></div> 
    <div class="field"> 
    <div class="GroupSelect"> 
<Input type = 'Checkbox' id="sn" Name='sn' class="sn" value="Yes" <?php echo 
(!empty($sn)) ? 'checked="checked"' : '';?> /><label for="sn"><span></span></label> 
</div> 
</div> 
</div> 

<p class="textareaStyle"> 
Health Problems or Allergies 
<textarea name="hp" value='<?php echo $hp; ?>' class="healthAllergyField" 
id="contact"></textarea> 
</p> 
</section> 
<section class="agreement"><?php echo $parentMessage; ?>     

<p class="bold"> 
PARENT/GUARDIAN AUTHORIZATION: 
</p> 
<section> 
<Input type = 'Checkbox' id="autho" Name ='authorization' class="authorization" value ="1" <?php echo 
(!empty($authorization)) ? 'checked="checked"' : '';?> /><label for="autho"><span></span>I understand the traffic 
safety education course consists of 30 clock-hours of classroom instruction, 6 
hours of behind-the-wheel instruction and 6 hours of in-car observation. I also 
understand that instruction is provided by a properly certified instructor licensed 
by the Idaho Department of Education and the Idaho Bureau of Occupational Licenses, 
and the behind-the-wheel training takes place in a dual-control vehicle that is 
adequately insured. I accept the fact that the Buckle-UP Driving School, LLC will 
not be responsible for any driving the student may do outside the Driver Education 
program. In addition I acknowledge that portions of the student participation in 
this traffic safety education course may be videotaped for feedback and grading as 
well as for use in future training courses. </label> 
</section> 
<section> 
<p> 
<input type="checkbox" id="parentPack" title="Packet" name="packet" value="1" <?php echo 
(!empty($packet)) ? 'checked="checked"' : '';?> /><label for="parentPack"><span></span>I have read the <a href= 
"pdf_server.php?file=pdfs/BUCKLE_UP_INFORMATION_PACKET" class="registerLink">Student/Parent or Guardian 
Information Packet</a><a href= 
"pdfs/BUCKLE_UP_INFORMATION_PACKET.pdf" class="registerLinkMobile">Student/Parent or Guardian 
Information Packet</a> for Driver Education and hereby give approval for the above 
student to participate in the course.</label> 
</p>  
</section> 
<div class="signature">  
<section> 
<p> 
<input type="checkbox" id="signature" title="Parent/Guardian Signature" name="signature" value="1" <?php echo 
(!empty($signature)) ? 'checked="checked"' : '';?> /><label for="signature"><span></span>By checking this box you are registering the above student for Driver's Education with Buckle-Up Driving School and are stating the above information is accurate to the best of your knowlegde. Any false statements or registration by anyone other than the Parent/Guardian can and will be held accountable by the laws within your State. The registration fee of $275 for class in Priest River/Sandpoint will need to be paid in full by the end of the class and $375 for the online class.</label> 
</p>  
</section> 
<input type="submit" name="submit" value="Send" class="formButton"> 
</div> 
</section> 
</form> 
+0

С какой ошибкой вы столкнулись? проверьте php_error_log или добавьте 'error_reporting (E_ALL); ini_set ('display_errors', 1); 'в начале вашего файла. – bcesars

+1

Слишком много кода. Направьте нас туда, где у вас возникли проблемы, и сообщите нам, какие ошибки возникают, что не происходит и т. Д. Если вы прокомментируете часть, которую вы только что добавили, проблема исчезнет? –

+0

Я не получаю сообщение об ошибке. ничего не приходит на адрес электронной почты – RyanIndustries8

ответ

0

, не видя многое другое можно увидеть проблему с проводки без действия и отвлекая действие к Фрагмент кода JavaScript, который не существует в коде, публикуемую на ваш вопрос. Таким образом, форма не будет размещаться, потому что следующее сообщение не позволяет, но отправить событие click на отсутствующий javascript.

action="#" onsubmit="myFunction();return false") 

Ваше сообщение слишком неполное для ответа. Но то, что я сделал, это удалить атрибуты оскорбления, чтобы вернуть форму в код.

Что вы должны сделать, так это то, что я сделал. Используйте Wampserver локально (Mamp, если на Mac). Затем сделайте одну страницу с кодом. Xdebug встроен в wampserver, поэтому вы получите мгновенную трассировку стека. Это поможет вам справиться с ошибками, которых слишком много, чтобы перечислять их здесь.

Использование firebug в Mozilla - тоже хорошая вещь. С вами вы увидите, что элемент отправки клика отправляет несуществующую или баггированную функцию javascript.

Смежные вопросы