Pass form field variables from one php file to another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dangaskin
Forum Newbie
Posts: 6
Joined: Thu Sep 16, 2010 6:26 pm

Pass form field variables from one php file to another

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post by Jonah Bron »

Could you show exactly where you want to insert it?
dangaskin
Forum Newbie
Posts: 6
Joined: Thu Sep 16, 2010 6:26 pm

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

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post 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?
dangaskin
Forum Newbie
Posts: 6
Joined: Thu Sep 16, 2010 6:26 pm

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

Post by dangaskin »

Yes. Thank you very much. I didn't think of doing it that way but that will work nicely.

Much appreciated,
Dan
Post Reply