jagreen78 Posted February 8, 2008 Share Posted February 8, 2008 Everything seems to work except my "select" list that I tried to add....and I don't know if it is capturing all the data once you hit the send button... <?php class maxContact { var $subjectText = "This message has been sent from the web site"; var $targetEmail = "mail@mail.com"; var $mailFormat = "text/plain"; var $fieldList; var $errorList; var $email = ''; var $name = ''; var $phone= ''; var $additionalText = ''; function maxContact(){ //Extend the list as you want here $this->fieldList[0]['caption'] = "City"; $this->fieldList[0]['fieldName'] = "city"; $this->fieldList[0]['value'] = ""; $this->fieldList[1]['caption'] = "State"; $this->fieldList[1]['fieldName'] = "state"; $this->fieldList[1]['value'] = ""; $this->fieldList[2]['caption'] = "Zip"; $this->fieldList[2]['fieldName'] = "zip"; $this->fieldList[2]['value'] = ""; } function showForm(){ $message = ''; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo ' <table>'; echo ' <tr><td>Name:</td>' .' <td><input type="text" name="name" value="'.$this->name.'" /></td></tr>'; echo ' <tr><td>Email:</td>' .' <td><input type="text" name="email" value="'.$this->email.'"/></td></tr>'; // Now display additional elements foreach ($this->fieldList as $value) { echo ' <tr><td>'.$value['caption'].':</td>' .' <td><input type="text" name="'.$value['fieldName'].'" value="'.$value['value'].'" /></td></tr>'; } echo ' <tr><td>Phone:</td>' .' <td ><input type="text" name="phone">'.$this->phone.'</textarea></td></tr>' echo ' <tr><td>Reason for contact:</td>' .' <td ><select name="reason" id="reason"> <option value="Annuities" selected="selected">Annuities</option> <option value="Life Insurance">Life Insurance</option> <option value="Long Term Care">Long Term Care</option> <option value="Medicare Supplement Insurance">Medicare Supplement Insurance</option> <option value="Health Insurance">Health Insurance</option> </select></td></tr>' .'<tr><td><input type="submit" name="submitBtn" class="sbtn" value="Send" /></td></tr>'; echo ' </table>'; echo '</form>'; } function sendMail() { $subject = $this->subjectText; $from = "From: $this->name <$this->email>\r\nReply-To: $this->email\r\n"; $header = "MIME-Version: 1.0\r\n"."Content-type: $this->mailFormat; charset=iso-8859-1\r\n"; $content = $this->message; if ($this->additionalText != ''){ $content .= "\r\n\r\nAdditional information:\r\n\r\n" .$this->additionalText; } $content = wordwrap($content,70); @mail($this->targetEmail,$subject,$content,$from.$header); } function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } } function processForm(){ if (isset($_POST['submitBtn'])){ $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $name = isset($_POST['name']) ? trim($_POST['name']) : ''; //$message = isset($_POST['message']) ? trim($_POST['message']) : ''; if (!$this->isValidEmail($email)) $this->errorList[] = "Invalid email address!"; if (strlen($name)<2) $this->errorList[] = "Invalid name! It must be at least 2 characters long."; //if (strlen($message)<5) $this->errorList[] = "Invalid message! It must be at least 10 characters long."; $this->email = $email; $this->name = $name; //$this->message = htmlspecialchars($message); foreach ($this->fieldList as $key=>$value) { if (isset($_POST[$value['fieldName']])) { $this->fieldList[$key]['value'] = $_POST[$value['fieldName']]; $this->additionalText .= $value['caption'] . " : " . $_POST[$value['fieldName']]."\r\n"; } } if (sizeof($this->errorList) > 0){ $this->showErrors(); $this->showForm(); } else { $this->sendMail(); $this->showInfo(); } } else { $this->showForm(); } } function showErrors(){ echo '<ul class="error">'; foreach ($this->errorList as $value) { echo " <li>$value</li>"; } echo "</ul>"; } function showInfo(){ echo "<p>Thanks for your message!</p>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90140-help-im-new-to-php-and-need-some-help-with-this-contact-form/ Share on other sites More sharing options...
BlueSkyIS Posted February 9, 2008 Share Posted February 9, 2008 "I don't know if it is capturing all the data once you hit the send button" can you expand on the problem? what do you mean by you don't know? what have you done to check? thx Quote Link to comment https://forums.phpfreaks.com/topic/90140-help-im-new-to-php-and-need-some-help-with-this-contact-form/#findComment-462240 Share on other sites More sharing options...
jagreen78 Posted February 9, 2008 Author Share Posted February 9, 2008 well first of all the more important problem is that once I added this code, the page went blank... echo ' <tr><td>Reason for contact:</td>' .' <td ><select name="reason" id="reason"> <option value="Annuities" selected="selected">Annuities</option> <option value="Life Insurance">Life Insurance</option> <option value="Long Term Care">Long Term Care</option> <option value="Medicare Supplement Insurance">Medicare Supplement Insurance</option> <option value="Health Insurance">Health Insurance</option> </select></td></tr>' And I KNOW NOTHING ABOUT PHP....I found this contact form and I am simply trying to piece my own contact form together from it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/90140-help-im-new-to-php-and-need-some-help-with-this-contact-form/#findComment-462242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.