×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

add a variable to subject in formmail.pl

add a variable to subject in formmail.pl

add a variable to subject in formmail.pl

(OP)
I have a web form that collects several pieces of information. I then send the results of the form to email via formmail.pl.
I would like to add the contents of one of the fields to the subject line in the email but can't seem to find the correct syntax.
Dan

RE: add a variable to subject in formmail.pl

Hi

Assuming you are talking about Matt Wright's formmail.pl, I would try to insert this after the &parse_form; call :

CODE --> Perl ( fragment )

$Config{'subject'} .= ' - ' . $Form{'some_field'}; 

Feherke.
feherke.github.io

RE: add a variable to subject in formmail.pl

(OP)
You are correct, I am using Matt's formmail.pl
I have changed the line as follows, but still not right:
<input type="hidden" name="subject" value="Reservation " + $Form.TConf >
I wan the subject to say "Reservation 2022 Jurisdictional" Where the form inputs "2022 Jurisdictional" to the variable T.Conf.
Thank you,
Dan

RE: add a variable to subject in formmail.pl

Hi

Not really what I tried to say. Forgot to mention that I assumed the HTML form contains an input for subject.

CODE --> formmail.pl ( fragment, lines 58-74 )

 58  # Check Referring URL
 59  &check_url;
 60 
 61  # Retrieve Date
 62  &get_date;
 63 
 64  # Parse Form Contents
 65  &parse_form;
 66 
     # Format the subject as you wish
     $Config{'subject'} = 'Reservation ' . $Form{'TConf'};
    
 67  # Check Required Fields
 68  &check_required;
 69 
 70  # Send E-Mail
 71  &send_mail;
 72 
 73  # Return HTML Page or Redirect User
 74  &return_html; 
If you have an older/adapted version of formmail.pl, the line numbers may not match, but hopefully you will identify the context from the surrounding lines.

Feherke.
feherke.github.io

RE: add a variable to subject in formmail.pl

(OP)
The version I am using is: nms FormMail © 2001 London Perl Mongers / Written as drop-in replacement for FormMail at Matt's Script Archive
It uses the following line to input the subject rather than a $Config statement:
<input type="hidden" name="subject" value="Order 2022">
Dan

RE: add a variable to subject in formmail.pl

Hi

Right.
  • And when you press submit, the browser sends the value of that and the other inputs to the web server.
  • The web server runs formmail.pl and passes it the received form data in a pretty raw format.
  • formmail.pl parses the raw form data :
    • Puts the e-mail details and configuration data in the %Config hash
    • Puts all other data in the %Form hash
    • Here I suggested to interfere and manipulate the subject
    • Checks that all necessary data was received
    • Composes the e-mail and sends it
    • Generates the result and sends it back to the browser

Feherke.
feherke.github.io

RE: add a variable to subject in formmail.pl

Hi

Thinking again, if you are not familiar with Perl, better handle it on client side :

CODE --> JavaScript ( fragment )

<input type="text" name="TConf" onchange="this.form.subject.value='Reservation '+this.value"> 
  • Add the highlighted part to the input you want to be added to the subject
  • It acts onchange, so when the input looses focus after its value was changed
  • Always replaces the entire subject, so if you want to change that "Reservation" word, you have to do it here
  • If the user not fills the input, then the subject will remain empty
Tried to keep it simple for now, but further fine tuning can be done if needed.

Here I put together a test case :

Feherke.
feherke.github.io

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close