• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Need to get the subject value from url at contact page

Jake Bunce

XenForo moderator
Staff member
#2
library/XenForo/ControllerPublic/Misc.php

Add the red code:

Code:
	public function actionContact()
	{
		$options = XenForo_Application::get('options');

		if ($options->contactUrl['type'] == 'custom')
		{
			return $this->responseRedirect(
				XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL,
				$options->contactUrl['custom']
			);
		}
		else if (!$options->contactUrl['type'])
		{
			return $this->responseRedirect(
				XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL,
				XenForo_Link::buildPublicLink('index')
			);
		}

		if ($this->_request->isPost())
		{
			if (!XenForo_Captcha_Abstract::validateDefault($this->_input))
			{
				return $this->responseCaptchaFailed();
			}

			$user = XenForo_Visitor::getInstance()->toArray();

			if (!$user['user_id'])
			{
				$user['email'] = $this->_input->filterSingle('email', XenForo_Input::STRING);

				if (!Zend_Validate::is($user['email'], 'EmailAddress'))
				{
					return $this->responseError(new XenForo_Phrase('please_enter_valid_email'));
				}
			}

			$input = $this->_input->filter(array(
				'subject' => XenForo_Input::STRING,
				'message' => XenForo_Input::STRING
			));

			if (!$user['username'] || !$input['subject'] || !$input['message'])
			{
				return $this->responseError(new XenForo_Phrase('please_complete_required_fields'));
			}

			$this->assertNotFlooding('contact');

			$mailParams = array(
				'user' => $user,
				'subject' => $input['subject'],
				'message' => $input['message']
			);

			$mail = XenForo_Mail::create('contact', $mailParams, 0);
			$mail->send(
				XenForo_Application::get('options')->contactEmailAddress, '', array(
					'Sender' => XenForo_Application::get('options')->contactEmailAddress
				),
				$user['email'], $user['username']
			);

			return $this->responseRedirect(
				XenForo_ControllerResponse_Redirect::SUCCESS,
				$this->getDynamicRedirect(),
				new XenForo_Phrase('your_message_has_been_sent')
			);
		}
		else
		{
			$viewParams = array(
				'redirect' => $this->getDynamicRedirect(),
				'subject' => $this->_input->filterSingle('subject', XenForo_Input::STRING),
				'captcha' => XenForo_Captcha_Abstract::createDefault()
			);

			return $this->responseView('XenForo_ViewPublic_Misc_Contact', 'contact', $viewParams);
		}
	}
That will enable you to use {$subject} inside of the contact template.
 

Jake Bunce

XenForo moderator
Staff member
#3
In the contact template, add the red code:

Code:
	<dl class="ctrlUnit">
		<dt><label for="ctrl_subject">{xen:phrase subject}:</label></dt>
		<dd><input value="{$subject}" type="text" name="subject" class="textCtrl" id="ctrl_subject" /></dd>
	</dl>
 

Jake Bunce

XenForo moderator
Staff member
#6
Its there any way to get the user ip address from the contact page?
And include it in the email? That's not a simple file edit. You really need an addon to extend the controller, define the additional param for the IP, and create a new email template.