Jump to content

Using the Contact form code for other Forms


Tylor Eddy

Recommended Posts

G'day Guys,

I am attempting to create 2 duplicates of the Contact form, and its php file, to create a training request form, and also a management positions application.

I am able to create the forms, they are the easy bit. What i'm stuck on is editing the contact.php (now training.php for the new module) to show the different fields in the form, and also display it differently in the email sent out after the form is completed.

This is what i have so far, to help explain what i wish to change.

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
*	Forums: http://www.phpvms.net/forum
*	Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
*/

class Training extends CodonModule 
{
public function index()
{
	require_once CORE_LIB_PATH.'/recaptcha/recaptchalib.php';


	if($this->post->submit)
	{
		if(Auth::LoggedIn() == false)
		{					
			# Make sure they entered an email address
			if(trim($this->post->name) == '' 
				|| trim($this->post->email) == '')
			{
				$this->set('message', 'You must enter a name and email!');
				$this->render('core_error.tpl');
				return;
			}
		}

		$resp = recaptcha_check_answer (Config::Get('RECAPTCHA_PRIVATE_KEY'),
			$_SERVER["REMOTE_ADDR"],
			$_POST["recaptcha_challenge_field"],
			$_POST["recaptcha_response_field"]);

		// Check the captcha thingy
		if(!$resp->is_valid)
		{
			$this->set('captcha_error', $resp->error);
			$this->set('message', 'You failed the captcha test!');
			$this->render('training_form.tpl');
			return;
		}

		if($this->post->subject == '' || trim($this->post->message) == '')
		{
			$this->set('message', 'You must enter a subject and message!');
			$this->render('core_error.tpl');
			return;
		}

		$subject = 'New message from '.$this->post->name.' - "'.$this->post->subject.'"';
		$message = DB::escape($this->post->message) . PHP_EOL . PHP_EOL;

		unset($_POST['recaptcha_challenge_field']);
		unset($_POST['recaptcha_response_field']);

		foreach($_POST as $field=>$value)
		{
			$message.="-$field = $value".PHP_EOL;
		}

		$message = nl2br($message);
		$message = utf8_encode($message);
		Util::SendEmail($this->post->recipient, $subject, $message);

		$this->render('training_sent.tpl');
		return;
	}		

	# Just a simple addition
	$rand1 = rand(1, 10);
	$rand2 = rand(1, 10);

	$this->set('rand1', $rand1);
	$this->set('rand2', $rand2);		

	$tot = $rand1 + $rand2;
	//echo "total: $tot <br />";
	SessionManager::Set('captcha_sum', $tot);

	//echo 'output of $_SESSION: <br />';
	//print_r($_SESSION);

	$this->render('training_form.tpl');
}

}

Near the center it says to display -$fields

I would like to change these fields so it displays different names for what is being presented, instead of subject & message in the email sent out. As it will confuse the staff member who gets the email

Also how can i call an extra field ?

Hopefully i've made sense here with what i've said haha

Cheers

Tylor

Currently the email looks like this:

12:30

-name = Tylor Eddy

-email = email here

-recipient = recipient email

-subject = 28.7.11

-message = 12:30

-loggedin = true

-submit = Send Message

i would like to change the fields to say

12:30

-name = Tylor Eddy

-email = email here

-recipient = recipient email

-Date = 28.7.11

-Time = 12:30

-loggedin = true

-submit = Send Message

and also get rid of the 12:30 displaying above the email

Link to comment
Share on other sites

Why you are not using one contact form but with a dropdown from which the sender have to choose the subject of his mail ? and also according to the subject you can use if...else statements to send the email to different receivers

I want to be able to use seperate forms for different area's within my site, that relay different information to various people in my management team, that's why i would like to have these two different forms.

Link to comment
Share on other sites

If all fails, it may actually be easier to just create two separate contact forms using a free service on the internet.

Saves a hell of a lot of work with coding and you can optimize it to your liking (i.e. drop downs etc.).

I looked into using one off the internet, I ran into trouble when it came to integrating it as a module. I've already created the forms, customised from the contact.tpl form, all that i need now is to customise the .php backend to send out the email with the new fields

Link to comment
Share on other sites

I looked into using one off the internet, I ran into trouble when it came to integrating it as a module. I've already created the forms, customised from the contact.tpl form, all that i need now is to customise the .php backend to send out the email with the new fields

Hmm I see, what I did was just get a nice looking script from the internet and instead of creating it as a module I created a page called "Contact Us" and pasted the script into that and voila :)

Sorry I can't really help the way you are doing it, but if you want to mak it slightly easier and try my way just let me know and I will be glad to help out.

Link to comment
Share on other sites

Hmm I see, what I did was just get a nice looking script from the internet and instead of creating it as a module I created a page called "Contact Us" and pasted the script into that and voila :)

Sorry I can't really help the way you are doing it, but if you want to mak it slightly easier and try my way just let me know and I will be glad to help out.

How did you call the fields, that's where i'm having the trouble. I'd be happy to see how you've done it, especially if its easier haha :)

Link to comment
Share on other sites

Try this:

This is an example for the proposed schedule

<body>
<form action="mailto:YOUR EMAIL@.COM?subject=YOUR SUBJECT" method="post" id="miomodulo" enctype="text/plain">

<label for="nome"><font color=yellow><b>DEPP ICAO</b></font></label><br />
<input type="text" id="DEPP ICAO" name="DEPP ICAO" size="20" />
<br />
<br />
<label for="cognome"><font color=yellow><b>ARR ICAO</b></font></label><br />
<input type="text" id="ARR ICAO" name=ARR ICAO" size="20" />
<br />
<br />
<label for="parere"><font color=yellow><b>DEP TIME</b></font></label><br />
<input type="text" id="DEP TIME" name="DEP TIME" size="20" />
<br />
<br />
<label for="parere"><font color=yellow><b>ARR TIME</b></font></label><br />
<input type="text" id="ARR TIME" name="ARR TIME" size="20" />
<br />
<br />
<label for="parere"><font color=yellow><b>Flight Time:</b></font></label> <br />
<input type="text" id="Flight Time:" name="Flight Time:" size="20" />
<br />
<br />

<font color=yellow><b>Days of Week:</b></font>
<br />

<label for="parere"><font color=yellow>sunday:</label>
<input type="Checkbox" id="sunday" name="sunday" size="20" />

<label for="parere">monday:</label>
<input type="Checkbox" id="monday" name="monday" size="20" />

<label for="parere">tuesday:</label>
<input type="Checkbox" id="tuesday" name="tuesday" size="20" />

<label for="parere">Wednesday:</label>
<input type="Checkbox" id="Wednesday" name="Wednesday" size="20" />

<label for="parere">Thursday :</label>
<input type="Checkbox" id="Thursday " name="Thursday " size="20" />

<label for="parere">Friday :</label>
<input type="Checkbox" id="Friday " name="Friday " size="20" />

<label for="parere">Saturday :</font></label>
<input type="Checkbox" id="Saturday " name="Saturday " size="10" />
<br />
<br />

<font color=yellow><b>Equipment: :</b></font><br />
<SELECT size=1 cols=4 NAME="Equipment">
<OPTION value=YOUR AIRCRAFT CODE > YOUR AIRCRAFT CODE

</select>
<br />
<br />
<label for="parere"><font color=yellow><b>FLIGHT LEVEL:</b></font></label><br />
<input type="text" id="FLIGHT LEVEL" name="FLIGHT LEVEL" size="20" />
<br />
<br />

<font color=yellow><b>Flight Type:</b></font><br />
<SELECT size=1 cols=4 NAME="Flight Type">
<OPTION value=Passenger> Passenger
<OPTION value=Cargo> Cargo
</select>
<br />
<br />
<label for="parere"><font color=yellow><b>price:</b></font></label><br />
<input type="text" id="Price" name="price" size="20" />
<br />
<br />

<font color=yellow><b>Route</b></font> <br />
<textarea cols="50" rows="4" WRAP="physical" name="Routes
"></textarea>
<br />
<br />

<font color=yellow><b>Notes</b></font><br />
<textarea cols="50" rows="4" WRAP="physical" name="Notes
"></textarea>
<br />
<br />

<input type="submit" value="send" />
<input type="reset" value="delete" />
</form>
</body>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...