2014-09-18 6 views
-3

Ce formulaire est pour un site web hébergé sur yahoo. Je sais qu'il accepte php parce que j'ai couru et test.php et c'est passé. Le formulaire ne va nulle part après avoir frappé soumettre sur le site Web de Yahoo. J'ai téléchargé sur un autre site et j'ai reçu un message d'erreur indiquant "Erreur d'analyse: erreur de syntaxe, T_STRING inattendu, attente de T_OLD_FUNCTION ou T_FUNCTION ou T_VAR ou"} "dans /home/ecdo02/public_html/emag/validate.class.php à la ligne 4 ". J'ai donc essayé sur mon propre site web hébergé par godaddy et sans erreurs, le formulaire a passé avec succès et il est apparu dans mon email. Est-ce que quelqu'un a une idée de ce qui se passe? C'est très étrange.Mon formulaire PHP fonctionne sur mon site Web godaddy hébergé, mais ne fonctionnera pas sur un site Web yahoo hébergé, comment puis-je corriger cela?

Ceci est mon request.php

<?php 
define("EMAIL", "[email protected]"); 

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

include('validate.class.php'); 

//assign post data to variables 
$firstname = trim($_POST['firstname']); 
$lastname = trim($_POST['lastname']); 
$company = trim($_POST['company']); 
$address = trim($_POST['address']); 
$city = trim($_POST['city']); 
$state = trim($_POST['state']); 
$zip = trim($_POST['zip']); 
$email = trim($_POST['email']); 
$phone = trim($_POST['phone']); 
$fax = trim($_POST['fax']); 
$title = trim($_POST['title']); 
$interest = trim($_POST['interest']); 
$comment = trim($_POST['comment']); 

//start validating our form 
$v = new validate(); 
$v->validateStr($firstname, "firstname", 3, 75); 
$v->validateStr($lastname, "lastname", 3, 75); 
$v->validateEmail($email, "email"); 
$v->validateStr($phone, "phone"); 
$v->validateStr($comment, "comment", 10, 500); 



//use php's mail function to send the email 
    @mail($email_to, $subject ,$message ,$header); 

    if(!$v->hasErrors()) { 
    $header = "From: $email\n" . "Reply-To: $email\n"; 
    $subject = "Lead from Website"; 
    $email_to = EMAIL; 

    $message = "A message was submitted. 

    From: $title $firstname $lastname 
    Company: $company 

    Address: $address 
    City: $city 
    State/ Province/ Region: $state 
    Postal/ Zip Code: $zip 

    E-mail: $email 
    Phone: $phone 
    Fax: $fax 

    What would you like? $interest 

    Comments: 
    $comment 

    -End of message 
    "; 


//grab the current url, append ?sent=yes to it and then redirect to that url 
    $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; 
    header('Location: '.$url."?sent=yes"); 

    } else { 
//set the number of errors message 
$message_text = $v->errorNumMessage();  

//store the errors list in a variable 
$errors = $v->displayErrors(); 

//get the individual error messages 
$firstnameErr = $v->getError("firstname"); 
$lastnameErr = $v->getError("lastname"); 
$phoneErr = $v->getError("phone"); 
$emailErr = $v->getError("email"); 
$commentErr = $v->getError("comment"); 
}//end error check 
} 
// end isset 

?> 

Ceci est mon validate.class.php

<?php 
class validate { 

    public $errors = array(); 

    public function validateStr($postVal, $postName, $min = 1, $max = 500) { 
if(strlen($postVal) < intval($min)) { 
    $this->setError($postName, ucfirst($postName)." field is required."); 
} else if(strlen($postVal) > intval($max)) { 
    $this->setError($postName, ucfirst($postName)." must be less than {$max} characters long."); 
    } 
}// end validateStr 


    public function validateEmail($emailVal, $emailName) { 
if(strlen($emailVal) <= 0) { 
    $this->setError($emailName, "Please enter an e-mail address"); 
} else if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a- zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $emailVal)) { 
    $this->setError($emailName, "Please enter a valid e-mail address"); 
    } 
    }// end validateEmail 


    /* Validate phone no to allow numbers only */  
    public function validatePhone($phoneVal, $phoneName) { 
    if (strlen($phoneVal) <= 0) { 
     $this->setError($phoneName, "Please enter your phone number"); 
    } else if (preg_match('/[^0-9]/', $phoneVal)) { 
     $this->setError($phoneName, "Please enter a valid phone number"); 
    } 
} // end validatephone 



/* sets an error message for a form element*/ 
    private function setError($element, $comment) { 
$this->errors[$element] = $comment; 
} 



    /* returns the error of a single form element*/ 
    public function getError($elementName) { 
if($this->errors[$elementName]) { 
    return $this->errors[$elementName]; 
    } else { 
    return false; 
    } 
} 

/* displays the errors as an html un-ordered list*/ 
public function displayErrors() { 
$errorsList = "<ul class=\"errors\">\n"; 
foreach($this->errors as $value) { 
    $errorsList .= "<li>". $value . "</li>\n"; 
} 
$errorsList .= "</ul>\n"; 
return $errorsList; 
} 


/* returns whether the form has errors*/ 
public function hasErrors() { 
if(count($this->errors) > 0) { 
    return true; 
} else { 
    return false; 
} 
} 



/* returns a string stating how many errors there were*/ 
    public function errorNumMessage() { 
if(count($this->errors) > 1) { 
     $message = "There were " . count($this->errors) . " errors sending your message!\n"; 
    } else { 
     $message = "There was an error sending your message!\n"; 
    } 
return $message; 
}// end hasErrors 

}// end class 

?> 

Voici la forme

<form id="contact_form" method="post" action="request.php"> 

        <fieldset> 
         <legend>Thank You</legend> 
         <div style="padding-left:100px">  

         <?php if(isset($_GET['sent'])): ?><table width="590" border="0"> 
    <tr> 
<td width="590" colspan="2"></td> 
    </tr> 
    <tr> 
<td colspan="2"> 
    <div style="padding:30px; text-align:center"><span style="font-size:24px; font-weight:bold;  ">Thank You!<br /><br /><span style="font-family:Arial, Helvetica, sans-serif; font-size:15px; background:; padding:20px; width:300px;text-align:center">Your submission has been submitted.</span></div> 
    </td> 
    </tr> 
    </table></div><?php endif; ?> 
    </fieldset> 





        <fieldset> 
         <legend>Request</legend> 
         <div style="padding-left:100px">  

         <table width="590" border="0"> 
    <tr> 
<td colspan="2"></td> 
    </tr> 
    <tr> 
<td colspan="2"></td> 
</tr> 
    <tr> 
<td width="195"><label>What would you like? </label></td> 
<td width="395"><select name="interest"> 
    <option value=""> -- Please select -- </option> 
    <option>Add me to your mailing list.</option> 
    <option>Send me an information kit.</option> 
    <option>Call me to set up a meeting.</option> 
    </select></td> 
    </tr> 
    </table></div> 
</fieldset> 
        <fieldset> 
       <legend>Personal Info</legend> 
        <div style="padding-left:100px;"> 
        <table width="590" border="0" cellpadding="10" cellspacing="5"> 
          <tr> 
          <td width="195" align="right"><label><b>Title</b></label></td> 
          <td width="395"><select name="title" style="width:183px"> 
    <option value=""> - Select Your Title - </option> 
    <option>Mr.</option> 
    <option>Mrs.</option> 
    <option>Miss</option> 
    <option>Ms.</option> 
    <option>Dr.</option> 
    <option>Prof.</option> 
    <option>Rev.</option> 
    <option>Other</option> 
</select> 
          </td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td>&nbsp;</td> 
          </tr> 
          <tr> 
          <td align="right"><label><b>First Name</b><span style="color: red">  *</span></label></td> 
          <td><input type="text" name="firstname" value="<?php echo htmlentities($firstname); ?>" />        <br /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $firstnameErr; ?></span></td> 
          </tr> 
          <tr> 
          <td align="right"><label><b>Last Name<span style="color: red">  *</span></b></label></td> 
          <td><input type="text" name="lastname" value="<?php echo htmlentities($lastname); ?>" />         <br /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $lastnameErr; ?></span></td> 
          </tr> 
          <tr> 
          <td><label><b>Company</b></label></td> 
<td><input type="text" name="company" value="<?php echo htmlentities($company); ?>" /></td> 

          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td>&nbsp;</td> 
         </tr> 
          <tr> 
          <td><label><b>Street Address</b><span style="color: red"> *</span>  </label></td> 
<td><input type="text" name="address" value="<?php echo htmlentities($address); ?>" /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $addressErr; ?></span></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td>&nbsp;</td> 
         </tr> 
          <tr> 
          <td><label><b>City</b><span style="color: red"> *</span></label>  </td> 
<td><input type="text" name="city" value="<?php echo htmlentities($city); ?>" /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $cityErr; ?></span></td> 
          </tr> 
          <tr> 
          <td><label><b>State</b><span style="color: red"> *</span></label></td> 
<td><input type="text" name="state" value="<?php echo htmlentities($state); ?>" />  <br /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $stateErr; ?></span></td> 
          </tr> 
          <tr> 
          <td><label><b>Postal/Zip Code</b><span style="color: red"> *</span>   </label></td> 
<td><input type="text" name="zip" value="<?php echo htmlentities($zip); ?>" />  <br /></td> 
          </tr> 
          <tr> 
          <td>&nbsp;</td> 
          <td><span class="errors"><?php echo $zipErr; ?></span></td> 
          </tr> 
        </table></div> 

        </fieldset> 
        <fieldset> 
         <legend>Contact Info</legend> 
         <div style="padding-left:100px;"> 

         <table width="590" border="0" cellpadding="10" cellspacing="5"> 
    <tr> 
     <td><label><b>E-mail</b><span style="color: red"> *</span></label></td> 
     <td><input type="text" name="email" value="<?php echo htmlentities($email); ?>" /></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td><span class="errors"><?php echo $emailErr; ?></span></td> 
    </tr> 
    <tr> 
<td><label><b>Phone</b><span style="color: red"> *</span></label></td> 
<td><input type="text" name="phone" value="<?php echo htmlentities($phone); ?>" /></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
    <td><span class="errors"><?php echo $phoneErr; ?></span></td> 
    </tr> 

    <tr> 
     <td width="195"><label><b>Fax</b></label></td> 
      <td width="395"><input type="text" name="fax" value="<?php echo htmlentities($fax); ?>" /> 
    </td> 
     </tr> 
    </table></div> 
        </fieldset> 
        <fieldset> 
          <legend>Additional Notes</legend> 

         <div style="padding-left:100px;"> 

         <table width="590" border="0" cellpadding="10"> 
     <tr valign="top"> 
     <td width="195"><label><b>Your Comment:</b></label></td> 
     <td width="395"><textarea name="comment" rows="10" cols="50" style="width: 300px;"/> 
     <?php echo htmlentities($comment); ?></textarea><br /> 
    <span class="errors"><?php echo $commentErr ?></span><br /></td> 
     </tr> 
    <tr> 
    <td>&nbsp;</td> 
<td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td> 
    </td> 
    </tr> 
    <tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
    </tr> 
<tr> 
<td>&nbsp;</td> 
<td><input type="submit" value="submit" name="submit" class="button" /></td> 
    </tr> 
    <tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
    </tr> 
         </table> 
     </div> 
       </form> 
+0

ne pas valider l'adresse e-mail avec une regex, utilisez 'filter_var ($ value, FILTER_VALIDATE_EMAIL)' à la place ... faites-moi confiance –

+0

J'ai vu cette question publiée aujourd'hui au moins 3 fois. Pourquoi gardez-vous la même question encore et encore? – Brad

+0

Le serveur Yahoo exécute une ancienne version de PHP qui ne peut pas gérer la nouvelle syntaxe. On dirait que PHP 4 là-bas. Découvrez comment basculer le serveur Yahoo pour utiliser une version plus récente de PHP. – deceze

Répondre

0

Faire vérifier phpinfo() sur les deux Yahoo et GoDaddy serveurs? Je m'attends à ce que votre serveur Yahoo fonctionne avec PHP 4.x tandis que votre serveur GoDaddy fonctionne avec PHP 5.x.

+0

PHP4? Est-ce que vous plaisantez? Yahoo a employé Lerdorf jusqu'en 2009, il va de soi qu'ils ont une version assez solide, et adaptée de PHP5 –

+0

J'ai vérifié et il a la dernière version de PHP 5.3 donc ce n'est pas un problème de version semble-t-il. – LRod

+1

Eh bien, quel genre d'erreur attendez-vous sur la ligne 'public $ errors = array();'? La différence de PHP 4 à 5 est 'var $ errors' à' public $ errors'. – Radhad

Questions connexes