Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add a variable to subject in formmail.pl

Status
Not open for further replies.

dan

MIS
Oct 7, 1998
298
US
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
 
Hi

Assuming you are talking about Matt Wright's formmail.pl, I would try to insert this after the [tt]&parse_form;[/tt] call :
Code:
[navy]$Config[/navy][teal]{[/teal][i][green]'subject'[/green][/i][teal]} .=[/teal] [i][green]' - '[/green][/i] [teal].[/teal] [navy]$Form[/navy][teal]{[/teal][i][green]'some_field'[/green][/i][teal]};[/teal]


Feherke.
feherke.github.io
 
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
 
Hi

Not really what I tried to say. Forgot to mention that I assumed the HTML form contains an [tt]input[/tt] for subject.
Code:
[COLOR=white gray] 58 [/color] [gray]# Check Referring URL[/gray]
[COLOR=white gray] 59 [/color] [teal]&[/teal]check_url[teal];[/teal]
[COLOR=white gray] 60 [/color]
[COLOR=white gray] 61 [/color] [gray]# Retrieve Date[/gray]
[COLOR=white gray] 62 [/color] [teal]&[/teal]get_date[teal];[/teal]
[COLOR=white gray] 63 [/color]
[COLOR=white gray] 64 [/color] [gray]# Parse Form Contents[/gray]
[COLOR=white gray] 65 [/color] [teal]&[/teal]parse_form[teal];[/teal]
[COLOR=white gray] 66 [/color]
[highlight green]    [/highlight] [gray]# Format the subject as you wish[/gray]
[highlight green]    [/highlight][navy] $Config[/navy][teal]{[/teal][i][green]'subject'[/green][/i][teal]} =[/teal] [i][green]'Reservation '[/green][/i] [teal].[/teal] [navy]$Form[/navy][teal]{[/teal][i][green]'TConf'[/green][/i][teal]};[/teal]
[highlight green]    [/highlight]
[COLOR=white gray] 67 [/color] [gray]# Check Required Fields[/gray]
[COLOR=white gray] 68 [/color] [teal]&[/teal]check_required[teal];[/teal]
[COLOR=white gray] 69 [/color]
[COLOR=white gray] 70 [/color] [gray]# Send E-Mail[/gray]
[COLOR=white gray] 71 [/color] [teal]&[/teal]send_mail[teal];[/teal]
[COLOR=white gray] 72 [/color]
[COLOR=white gray] 73 [/color] [gray]# Return HTML Page or Redirect User[/gray]
[COLOR=white gray] 74 [/color] [teal]&[/teal]return_html[teal];[/teal]
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
 
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
 
Hi

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

Feherke.
feherke.github.io
 
Hi

Thinking again, if you are not familiar with Perl, better handle it on client side :
Code:
[teal]<[/teal]input type[teal]=[/teal][i][green]"text"[/green][/i] name[teal]=[/teal][i][green]"TConf"[/green][/i] [highlight]onchange[teal]=[/teal][i][green]"this.form.subject.value='Reservation '+this.value"[/green][/i][/highlight][teal]>[/teal]
[ul]
[li]Add the [highlight]highlighted[/highlight] part to the [tt]input[/tt] you want to be added to the subject[/li]
[li]It acts [tt]onchange[/tt], so when the [tt]input[/tt] looses focus after its value was changed[/li]
[li]Always replaces the entire subject, so if you want to change that "Reservation" word, you have to do it here[/li]
[li]If the user not fills the input, then the subject will remain empty[/li]
[/ul]
Tried to keep it simple for now, but further fine tuning can be done if needed.

Here I put together a test case :
[ul]
[li]Go to fill the form and submit it[/li]
[li]Go to and see how the form data was received[/li]
[/ul]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top