Page 1 of 1

Pass form field variables from one php file to another

Posted: Thu Sep 16, 2010 6:40 pm
by dangaskin
Hi,

I am relatively new to php and I have a client that has a job board on their website. When the applicant applies for a job, confirmation emails need to be sent. The website is built with the Drupal CMS and a job postings module has been installed. The module already has the function to send emails, however, the messages are stored inside the module file. I would like to have the emails in an external file.

What I am looking to do is have the confirmation email to the company with the fields the user fills out. E.g. $user for username.

To the module file I have added the following code to read the email file.

Code: Select all

function job_posting_mail($key, &$message, $params) {
  $language = $message['language'];
  switch ($key) {
    case 'application':
	    $message_bod = ""
		$application = fopen ("naa.email.txt", "r");
			if ($application) {
				while (!feof($application)) {
					$buffer = fgets($application, 4096);
					$message_body .= $buffer;
				}
				fclose($application);
			}
      $message['headers']['Content-Type'] = $params['content-type'];
      $message['subject'] = t('!subject', array('!subject' => $params['subject']),
        $language->language);
      $message['body'] = $message_bod = ""
      break;
What I don't know how to do is add the form fields to the email file. If someone could give me a quick example using the $user variable it would be greatly appreciated.

Thank you very much,
Dan

Re: Pass form field variables from one php file to another

Posted: Thu Sep 16, 2010 6:49 pm
by Jonah Bron
Could you show exactly where you want to insert it?

Re: Pass form field variables from one php file to another

Posted: Thu Sep 16, 2010 9:27 pm
by dangaskin
At the moment there are 2 files. Job_postings.module and the email file called naa.email.txt.

The job_postings.module is set up perfectly to read the naa.email.txt file. I am just unsure as to how I get the variables that are filled out when the job_postings.module is run to be inserted in the naa.email.txt file.

At the moment the naa.email.txt is virtually blank. All that I have in it is:

Code: Select all

<?php
$naamessage = "A new application has been received. The applicant filled out the following details:";
?>
And then I just want to simply listed all the variables that the user filled out from the job_posting.module file. The module file has about 1400 lines of code so I don't think it is worth posting the whole thing.

Thank you very much for your help :D ,
Dan.

Re: Pass form field variables from one php file to another

Posted: Thu Sep 16, 2010 11:55 pm
by Jonah Bron
Sounds like you just want to know how to insert the contents of a variable into another string. The most common way to do it is like this:

Code: Select all

$user = "John Doe";
$hey = "Hey, " . $user . "!  How's it going?";
echo $hey;// outputs "Hey, John Doe!  How's it going?"
Is that what you're asking?

Re: Pass form field variables from one php file to another

Posted: Fri Sep 17, 2010 12:01 am
by dangaskin
Yes. Thank you very much. I didn't think of doing it that way but that will work nicely.

Much appreciated,
Dan