1
votes

I have searched as suggested but have not found why my version of the form does not work. I have a form that collects name, email, phone, a select option and a message in a textarea input. I change the textarea and action php based off the user option selected in the select input.

I use PHP to email the form contentse. I get ALL fields except for: -Message/Comments

HTML

<!-- Career Form -->
<form id="careerContactForm" role="form" action="" method="post" enctype="multipart/form-data">
  <!-- $name -->
  <div class="row form-group">
    <div class="col-md-8 col-md-offset-2 required">
      <label for="contact-name">Full Name</label>
      <input type="text" name="name" class="form-control" id="contact-name" placeholder="Full Name" required>
    </div>
  </div>
  <!-- $email -->
  <div class="row form-group">
    <div class="col-md-4 col-md-offset-2 required">
      <label for="contact-email">Email</label>
      <input type="text" name="email" class="form-control" id="contact-email" placeholder="Email" required>
    </div>
    <!-- $phone -->
    <div class="col-md-4 required">
      <label for="contact-phone">Phone Number</label><br />
      <input type="text" class="form-control bfh-phone" data-country="US" id="contact-phone" name="phone" placeholder="Phone Number" required>
    </div>
  </div>
  <!-- $who -->
  <div class="row form-group">
    <div class="col-md-8 col-md-offset-2 required select-wrapper">
    <!-- Contact -->
      <label for="contact-who">Who are you trying to contact?</label>
      <select class="selectorWho form-control" name="who" required>
        <option value="None"><em>--Please Select One--</em></option>
        <option value="general">General</option>
        <option value="HR / Careers">HR / Careers</option>
        <option value="sales">Sales</option>
        <option value="td">TDXperts</option>
        <option value="Other">Other</option>
      </select>
    </div>
  </div>
  <!-- $interest -->
  <div class="row form-group hidden uploadResume">
    <div class="col-md-8 col-md-offset-2 required select-wrapper">
     <!-- Career -->
      <label>I'm looking for employment opportunities in…</label>
      <select class="selector-career form-control" name="interest" required>
        <option value="None"><em>--Please Select One--</em></option>
        <option value="Accounting">Accounting</option>
        <option value="Administration">Administration</option>
        <option value="Finance">Finance</option>
        <option value="general">General</option>
        <option value="HR">HR</option>
        <option value="IT">IT</option>
        <option value="Logistics & Customs Affairs">Logistics & Customs Affairs</option>
        <option value="Marketing">Marketing</option>
        <option value="Purchasing">Purchasing</option>
        <option value="Sales">Sales</option>
        <option value="Supply Chain Planning">Supply Chain Planning</option>
        <option value="Warehouse">Warehouse</option>
        <option value="Other">Other</option>
      </select>
    </div>
    <div class="col-md-8 col-md-offset-2 required">
      <label for="uploadResume">Upload Your Resume</label>
      <input type="file" name="resume" id="resume-upload">
      <p class="help-block"><em>You must choose a valid file. We accept .doc, .docx, .pdf, .rtf and .txt files</em></p>
    </div>
  </div>
  <!-- Career Submit: hide / show -->
  <div class="row form-group">
    <div class="col-md-8 col-md-offset-2 hidden careerContact">
      <!-- Contact -->
      <label for="contact-message">Questions or Comments</label>
      <textarea name="message" cols="50" rows="6" id="contact-message" class="form-control" placeholder="Would you like to include any more information?" ></textarea>
    </div>
    <div class="col-md-8 col-md-offset-2 hidden contactMessage">
      <!-- Career -->
      <label for="career-message">Message</label>
      <textarea name="comments" cols="50" rows="6" id="career-message" class="form-control" placeholder="Your message..." ></textarea>
    </div>
  </div>
  <div class="row form-group">
    <div class="col-md-8 col-md-offset-2">
      <button type="submit" class="btn">Send message</button>
    </div>
  </div>
</form>

JS (that show/hide textareas and show/hide file upload dialog)

$(document).ready(function(e) {
$(".selectorWho").on('change', function(e) {
    e.preventDefault();
    var uploadResume = $('.uploadResume');
    var comments = $('.contactMessage');
    var careerComments = $('.careerContact');
    if (this.value == "HR / Careers") {
        uploadResume.slideDown().removeClass("hidden");
        careerComments.removeClass("hidden");
        comments.addClass("hidden");
        var action = "do/careers-submit.php";
        var submitButton = 'career-submit';
    } else {
        uploadResume.slideUp().addClass('hidden');
        careerComments.addClass('hidden');
        comments.removeClass("hidden");
        var action = "do/contact-submit.php";
        var submitButton = 'contact-submit';
    }
    $("#careerContactForm").attr("action", action);
});
});

PHP (for one of the actions)

<?php 
    require("../classes/class.phpmailer.php");
    $mail = new PHPMailer();

    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $who = $_POST['who'];
    $interest = $_POST['interest'];
    $comments = $_POST['comments'];

    $mail->IsSMTP();
    $mail->From     = "$email";
    $mail->FromName = "$name";
    // $mail->AddAddress("[email protected]","Tireco HR");
    $mail->AddAddress("[email protected]","Tireco HR");
    $mail->Subject  = "New Resume Submission";
    $mail->Body     = "Name:\n $name\n\n\nPhone:\n $phone\n\n\nEmail:\n $email\n\n\nContacting:\n $who\n\n\nInterested In:\n -$interest\n\n\nQuestions/Comments:\n $comments";

    if (isset($_FILES['resume']) &&
        $_FILES['resume']['error'] == UPLOAD_ERR_OK) {
        $mail->AddAttachment($_FILES['resume']['tmp_name'],
                         $_FILES['resume']['name']);
    }

    $mail->WordWrap = 50;

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
        header( 'Location: ../thankYou.html' ) ;
    }
?>

So, I get all fields except for the message/comments textarea text.

If you would like to see what I get in the email click here

If you clicked, you saw what I get when I submit a HR/Careers > IT + Upload File + Message...The message is omitted.

Thank you in advance for your help.

VS

2
What is this code NOT doing that you need it to do? What kind of output are you getting vs. what you expect? Do you have PHP errors turned on? - user5952891
Thank you for your reply. I need the form to email me name, email, phone, "interest" (select option) and a coimments/message. I am receiving a mail with only the name, email and phone. I need to receive he textarea with comments and the option they selected in the select input. How do I turn PHP errors "on?" - vs-works
Go to your php.ini file in your PHP directory. About 250 to 400 lines down you will find a section labeled 'Error handling and logging'. Go down to the 'Common Values' option and uncomment "E_ALL & ~E_NOTICE | E_STRICT' and remove any following text. This will show all errors, except for notices. You will have to re-boot for this to work. - user5952891

2 Answers

0
votes

You need to give your select box a name, not the option.

You have

<select id="interest" class="selector-career form-control" required>

It needs to be

<select name="interest" id="interest" class="selector-career form-control" required>

With regards to the file attachment you should probably check the file uploaded ok

if (isset($_FILES['resume']) &&
    $_FILES['resume']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['resume']['tmp_name'],
                         $_FILES['resume']['name']);
}
0
votes

This is what I use for my selectors, which I have inside a div / form wrapper.
You need to select an index of the option, not the option container.
This is for selecting States, of which I have removed most to save space. Look at it's structure and modify your code.
Notice the square brackets that index the option your client selected. "state_sel" is the variable that contains the selected item. I left out my button for a function call.

 <form id="state_opt" name="state_opt">&nbsp;State
<select id="state_mgr" onChange="state_sel=document.state_opt.state_mgr.options[document.state_opt.state_mgr.selectedIndex].value;">
<option selected value="0">None</option>
<option value="AL">Alabama
<option value="MT">Montana
<option value="WI">Wisconsin
<option value="MO">Missouri
<option value="WY">Wyoming
</select>