Jump to content

Form Redirection


Recommended Posts

Hello ( £15 for the fix if anyone can help me achieve this )

 

i am trying to redirect customers to login / registration after they have submitted their request on my custom homepage form.

 

The options i have at the moment is either to allow all visitors to submit the form which i can see their requests in the back office or allow only registered customers to submit the form otherwise non registered customers they are sent to the login / registration page without capturing the data submitted from the form

 

i want to be able to allow all visitors to submit the form but only redirect unregisterd customers to the registration page. ( but capture all data from form submissions )

 

i take this will be a condition expression needed but i dont know what and how to edit.

 

here is my code in indexcontroller.php

 

A preferred thank you message would also be an advantage with maybe a link to registration if the visitor is not already registered.

 

I appreciate any support offered

 

Thanks Chris

public function initContent()
	{
		$customer = $this->context->customer;
        if (Tools::isSubmit('sendmail'))
		{
			$posData = array();
			$posData = $_POST;
			$saveArray = array();
			if(!empty($customer->id))
			/
				$customer = json_decode(json_encode($customer),true);
				$id_shop = 1;//$customer['id_shop'];
				$id_lang = 1;//$customer['id_lang'];
				$email   = $_POST['email'];
				$id_customer = 0;//$customer['id'];
				$status     = 'open';
				$dateadd 	= date('Y-m-d H:i:s');
				$dateupdate 	= date('Y-m-d H:i:s');	
				/*$token    = otpKey(9);*/
                                 
				$unique_num = '';
				$keys = array();
			    $keys  = array_merge(range(0, 9), range('A', 'Z'));
			    
			    for ($i = 0; $i < 8; $i++) {
			        $unique_num .= $keys[array_rand($keys)];
			    }
				$token  = $unique_num; 

				Db::getInstance()->executeS("INSERT INTO `ps_customer_thread`(`id_shop`, `id_lang`, `id_contact`, `id_customer`, `id_order`, `id_product`, `status`, `email`, `token`,date_add,date_upd) VALUES ($id_shop,$id_lang,0,$id_customer,0,0,'".$status."','".$email."','".$token."','".$dateadd."','".$dateupdate."')",'INSERT');
				$id_customer_thread = Db::getInstance()->Insert_ID(); 
				//echo $id_customer_thread;
				//$message = $_POST['message'];
				$parts = $_POST['products'];
				$parts = implode(",", $parts);
				$message = '';
				$message = "To Bob & Chris - Customer : ".$_POST['firstName']." ".$_POST['lastName']." has requested a quote for parts on the following Vehicle Registration: (".$_POST['vehicle_registration'].") - Vehicle Make: (".$_POST['vehicle_make'].") - Vehicle Model (".$_POST['vehiclemodel'].") - Parts Requested : ( ".$parts." ). - Customers Message: ".$_POST['message'].". - Respond to customer at: ".$_POST['email'].".";
				
				Db::getInstance()->executeS("INSERT INTO `ps_customer_message`(`id_customer_thread`, `id_employee`, `message`,  `date_add`, `date_upd`) VALUES ($id_customer_thread,0,'".$message."','".$dateadd."','".$dateupdate."') ");	
			}
			else
			{
				header('Location: http://............../login');
			}
		}
Edited by Stokie Worm (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...