Hi,

Need a little help with the subject field of a form (using Yahoo webhosting). I am currently using

<input type="hidden" name="subject" value="Form">

and it works just fine but I would like to add a two field values that the user has previously entered into the subject line. The fields are pick_up_month and pick_up_date, so the completed subject line would look like: Form 6/11.

Thanks in advance.

Dani AI

Generated

Short answer: use JavaScript to build the subject from your month and date selects and write that string into the hidden subject field just before the form is submitted. That gives you the "Form 6/11" style subject in the email without changing your existing dropdowns.

As already has dropdowns and suggested JavaScript, here's a minimal pattern to follow — bind to the form submit (or to the selects' change events to keep the hidden value in sync) and set the hidden field value programmatically.

document.addEventListener('DOMContentLoaded', function () {
  var f = document.getElementById('yourFormId');
  var month = document.getElementById('pick_up_month');
  var day = document.getElementById('pick_up_date');

  f.addEventListener('submit', function () {
    var subject = 'Form ' + month.value + '/' + day.value;
    var h = document.querySelector('input[name="subject"]');
    if (h) h.value = subject;
  });
});

Practical tips:

  • Make sure the element IDs/names in the script match your form. If the script runs before the elements exist the value will not be set — either place the script at the end of the page or use DOMContentLoaded as above.
  • Format the values how you want (month names vs numbers, zero-pad day with ('0'+day).slice(-2), etc.) before assigning the subject.
  • Avoid newlines or very long strings in the subject. Test by submitting to a controlled address and inspect the raw message to confirm the subject changed.

If the mail you receive still shows the old subject, the host-side mail handler may be overriding or ignoring that field; in that case review the host form-mail documentation or the form-processing script to see what field name it accepts for subject.

Recommended Answers

All 3 Replies

Why not just have a dropdown box with the options of all the months and dates? That seems a bit more logical.

I have about 15 different input fields in the form including pick up month and date as drop down boxes. The form is working fine, just trying to figure out how to show them in the subject line as well as in the body of the email I receive.

You would need javascript i believe.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.