Using form variables in subject, and email body

Post any questions you may have here

Using form variables in subject, and email body

Postby MasterC on Tue Mar 25, 2008 10:51 pm

Hi,

I've got a form that requests information from our student and emails it to our advisors. For now this function is all I'm working on, later I'd like to instead be able to save it to a database and email a link of the saved form instead of the contents of the form. I'm interested in how I should use form data for email variables. I have seen this thread:
http://www.chronoengine.com/index.php?o ... 72&catid=2

And I've seen the tutorial, but I must be missing something "obvious" somewhere. I have these fields in my Form HTML:
Code: Select all
<td>Name:</td>
      <td colspan="3"><input name='name' type='text' size="30" /></td>
    </tr>
    <tr>
      <td>Student ID: </td>
      <td colspan="3"><input name='studentID' type='text' size="20" /></td>
    </tr>
    <tr>
      <td>Email address: </td>
      <td colspan="3"><input name='email' type='text' size="40" /></td>

I'll be transforming it to a CSS-based layout later, so please just ignore the table formatting for now :)

And then in the second tab called "Special Fields" I have subject name and email in the corresponding fields. Then in the next tab in the OnSubmit before email is sent I have the following PHP code:
Code: Select all
<?php $_POST['subject'] = "Major Status application for" $_POST['name'] ?>


Yet when I fill out the form with a name, ID and email address, I only get the name and email variables working (they show up in the From line); the subject is always blank. If I remove the OnSubmit code, the special fields "subject" and put something in the General subject box, it gets passed through appropriately.

Is it something wrong with my PHP code? Any help would be appreciated!

-Chad
MasterC
Fresh Boarder
 
Posts: 9
Joined: Tue Mar 25, 2008 3:37 pm

Re:Using form variables in subject, and email body

Postby GreyHead on Wed Mar 26, 2008 12:54 am

Hi Chad,

The problem is that ChronoForms doesn't know that you are creating a field called 'subject'. Add a hidden field to your form:
Code: Select all
<input type="hidden' name="subject" value="" />
Then ChronoForms will create a placeholder that will be filled in by your OnSubmit code.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:Using form variables in subject, and email body

Postby MasterC on Wed Mar 26, 2008 11:46 pm

Thank you! You did mention that in the above referenced thread, I guess I just didn't see it or understand what it did enough to pay attention to that. Thanks again!

-Chad
MasterC
Fresh Boarder
 
Posts: 9
Joined: Tue Mar 25, 2008 3:37 pm

Re:Using form variables in subject, and email body

Postby MasterC on Fri Mar 28, 2008 5:30 am

I must have some typo that I'm not seeing, but I still cannot seem to get a subject when I use variables from my form. Just to recap what I've done:

In the General section:
Subject: subject
From Email: email
From name: name

In the Special Fields section:
subject field: subject
From email field: email
From name field: name

In the HTML of my form:
Code: Select all
<input type="hidden" name="subject" value="" />
<label for="name">Name:</label><input name='name' id='name' type='text'/>
<label for="studentID">Student ID:</label><input name='studentID' id='studentID' type='text' />
<label for="email">Email address:</label><input name='email' id='email' type='text' />


And when I feel out my form and hit submit, the subject field of my email is still blank.

Any ideas?

Thanks!

-Chad
MasterC
Fresh Boarder
 
Posts: 9
Joined: Tue Mar 25, 2008 3:37 pm

Re:Using form variables in subject, and email body

Postby GreyHead on Fri Mar 28, 2008 5:41 am

Hi chad,

Do you have the other code in the 'OnSubmit before' box?

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3253
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:Using form variables in subject, and email body

Postby MasterC on Fri Mar 28, 2008 6:00 am

:) Yes I do, thanks for asking.

Onsubmit before email is sent:
Code: Select all
<?php $_POST['subject'] = Intermediate Status application for $_POST['name'] ?>


And I've tried with and without quotes around my text:
Code: Select all
<?php $_POST['subject'] = "Intermediate Status application for" $_POST['name'] ?>


Thanks!

-Chad

Post edited by: MasterC, at: 2008/03/28 02:01<br><br>Post edited by: MasterC, at: 2008/03/28 02:02
MasterC
Fresh Boarder
 
Posts: 9
Joined: Tue Mar 25, 2008 3:37 pm

Re:Using form variables in subject, and email body

Postby admin on Fri Mar 28, 2008 7:02 pm

Hi Chad,

It should be :

Code: Select all
<?php $_POST['subject'] = "Intermediate Status application for".$_POST['name'] ?>
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 2313
Joined: Mon Aug 14, 2006 5:29 am

Re:Using form variables in subject, and email body

Postby MasterC on Sat Mar 29, 2008 2:47 am

Indeed! I forgot to concatenate, much appreciated.

-Chad
MasterC
Fresh Boarder
 
Posts: 9
Joined: Tue Mar 25, 2008 3:37 pm


Return to ChronoForms Questions & Answers

Who is online

Users browsing this forum: Google [Bot] and 8 guests