1. 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

Discussion in 'XenForo Development Discussions' started by Binu, May 17, 2013.

  1. Binu

    Binu Member

    Hi
    I need to get the subject value from url in the contact page.

    Tried alot by passing http://www.sitename.com/misc/contact?subject="Feedback"

    Even tried to change the html template. But its not accepting the php code to get the query string.

    Anybody help please

    Binu
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
    rafass, MJD and Binu like this.
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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>
    
     
    rafass, MJD and Binu like this.
  4. Binu

    Binu Member

    Thanks Jake, it works fine.
     
  5. Binu

    Binu Member

    Its there any way to get the user ip address from the contact page?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  7. Binu

    Binu Member

    Thanks.
     

Share This Page