Form Help

Discussion in 'PHP' started by The_FNG, Aug 17, 2007.

  1. #1
    I have a simple form on my site that just emails me the information when submitted. Currently, after the form is submitted, it displays the text "thank you your form has been submitted successfully. I would like to have the user directed back to my home page after submitting the form. Can anyone tell me how I might go about doing that?
     
    The_FNG, Aug 17, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Insert these 2 lines after the form processing is done.

    
    header('Location: http://example.com/');
    exit();
    
    PHP:

    If you need more specific help, post your code. (And don't forget the
     tags)
    PHP:
     
    nico_swd, Aug 17, 2007 IP
  3. The_FNG

    The_FNG Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It looks as if I should have been more specific. I have attached the form and php code.
     

    Attached Files:

    The_FNG, Aug 17, 2007 IP
  4. Muhammad Haris

    Muhammad Haris Peon

    Messages:
    576
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The script is way ugly. I've just browsed at the end and found the confirmation message then I added the header function and redirected the page to index.php after that confirmation message is displayed.
    
    <html>
    <head>
    <title>PHP Mail from GoldMine</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    /******************************************************
    *******************************************************
    ** PHPMailer.php
    ** written by JCS
    ** Purpose:
    **		This script was generated 
    **		with the GoldMine Web Import 
    **		script generator. It will generate
    **      the INI style of web import data 
    **      and email the results to the contact
    **		entered in the tool.
    **
    **  WARNING: This script requires that you
    **  have proper setup of your Apache server to
    **		A. use PHP
    **		B. setup of your PHP mailer for your SMTP data.
    *******************************************************
    *******************************************************
    */
    function Decode($strValueIn)
    {
    //Do not modify this function!
    $intX = 0;
    $intY = 0;
    $Temp = "";
    $Mod = "";
    $intMod =0;
    $intTemp = 0;
    $ValueOut = "";
    $intY = 1;
    $strValueOut="";
    for ($intX=1; $intX<=((strlen($strValueIn)/2)/2); $intX=$intX+1)
      {
    
        $strTemp="";
        $strMod="";
        if (($intX % 2)==0)
        {
    
          $strMod=substr(substr($strValueIn,$intY-1,4),0,2);
          $strTemp=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2));
        }
          else
        {
    
          $strMod=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2));
          $strTemp=substr(substr($strValueIn,$intY-1,4),0,2);
        } 
    
        $intMod=hexdec($strMod);
        $intTemp=hexdec($strTemp);
        $intTemp=$intTemp-$intMod;
        $strValueOut=$strValueOut.chr($intTemp);
        $intY=$intY+4;
    
      } 
    
      return $strValueOut;
    
    
    
    }
    
    if ($_POST["GMsubmit"]!="")
    {
    	$Body = "";
    	//$SendToEmail = Decode($_POST["SendToEmail"]);
    	//$SMTP = Decode($_POST["SMTP"]); //Your SMTP data may have to be set set on the Apache Server, and this variable is not used.
    	$OnNewSendGMEmail = $_POST["OnNewSendGMEmail"];
    	if ($OnNewSendGMEmail!="")
    		{$OnNewSendGMEmail = Decode($OnNewSendGMEmail);}
    	else 
    		{$OnNewSendGMEmail = "";}
    	
    	if ($_POST["OnDUPSendGMEmail"]!="")
    		{$OnDUPSendGMEmail = Decode($_POST["OnDUPSendGMEmail"]);}
    	else 
    		{$OnDUPSendGMEmail = "";}
    	if ($_POST["OnNewAttachTrack"]!="")
    		{$OnNewAttachTrack = Decode($_POST["OnNewAttachTrack"]);}
    	else 
    		{$OnNewAttachTrack = "";}
    	if ($_POST["OnDupAttachTrack"]!="")
    		{$OnDupAttachTrack = Decode($_POST["OnDupAttachTrack"]);}
    	else 
    		{$OnDupAttachTrack = "";}
    	if ($_POST["Word"]!="")
    		{$Password = Decode($_POST["Word"]);}
    	else 
    		{$Password = "";}
    	if ($_POST["DupLogic"]!="")
    		{$DupLogic = Decode($_POST["DupLogic"]);}
    	else 
    		{$DupLogic = "";}
    	
    	$OutputAs = $_POST["OutPutAs"];
    	$DuplicateCount=0;
    	$XML = "<gmdata>";
    	
    	if ($_POST["DuplicateCount"]!="") 
    	{
    		$DuplicateCount =intval($_POST["DuplicateCount"]);
    		
    	}
    	if ($DuplicateCount >0 || $OnNewSendGMEmail!="" || $OnDUPSendGMEmail!="" ||
    		$OnNewAttachTrack!="" || $OnDupAttachTrack!="")
    	{
    		$Body = $Body."[Instructions]\n";
    		$XML = $XML."<Instructions>";
    		if ($DuplicateCount > 0)
    		{
    			for($counter=0; $counter < $DuplicateCount; $counter++)
    			{
    				$RealCount=$counter+1;
    				$str = "DuplicateChecking$RealCount";
    				eval("\$str = \"$str\";");
    				$Body = $Body."DupCheck".$RealCount."=".$_POST[$str]."\n";
    				//print($str.":".$_POST[$str].";");
    				$tempVal = $_POST[$str];
    				if ($tempVal==="EMAIL")
    				{
    					$XML = $XML."<DupCheck>EA1</DupCheck>";
    				}
    				else
    				{
    					if ($tempVal==="WEBSITE")
    					{
    						$XML = $XML."<DupCheck>WS1</DupCheck>";
    					}
    					else
    					{
    						$XML = $XML."<DupCheck>".htmlspecialchars($_POST[$str])."</DupCheck>";
    					}
    				}
    			}
    			if ($DupLogic !="")
    			{$Body = $Body."DupLogic=OR\n";}
    		}
    		if ($OnNewSendGMEmail!="")
    		{
    			$Body = $Body."OnNewSendGMEmail=".$OnNewSendGMEmail."\n";
    			$XML = $XML."<OnNewSendGMEmail>".htmlspecialchars($OnNewSendGMEmail)."</OnNewSendGMEmail>";
    			
    		}
    		if ($OnDUPSendGMEmail!="")
    		{
    			$Body = $Body."OnDUPSendGMEmail=".$OnDUPSendGMEmail."\n";
    			$XML = $XML."<OnDupSendGMEmail>".htmlspecialchars($OnDUPSendGMEmail)."</OnDupSendGMEmail>";
    			
    		}
    		if ($OnNewAttachTrack!="")
    		{
    			$comma =strpos($OnNewAttachTrack, ",");
    			$Body = $Body."OnNewAttachTrack=".$OnNewAttachTrack."\n";
    			if ($comma =="")
    			{
    				$XML = $XML."<OnNewAttachTrack>".htmlspecialchars($OnNewAttachTrack)."</OnNewAttachTrack>";
    			}
    			else
    			{
    				list($track, $user) = split(',', $OnNewAttachTrack,2);
    				$XML = $XML."<OnNewAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnNewAttachTrack>";
    			}
    		}
    		if ($OnDupAttachTrack!="")
    		{
    			$comma =strpos($OnDupAttachTrack, ",");
    			$Body = $Body."OnDupAttachTrack=".$OnDupAttachTrack."\n";
    			if ($comma =="")
    			{
    				$XML = $XML."<OnDupAttachTrack>".htmlspecialchars($OnDupAttachTrack)."</OnDupAttachTrack>";
    			}
    			else
    			{
    				list($track, $user) = split(',', $OnDupAttachTrack,2);
    				$XML = $XML."<OnDupAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnDupAttachTrack>";
    			}
    			
    			
    		}
    		if ($Password!="")
    		{
    			$Body = $Body."Password=".$Password."\n";
    			$XML = $XML."<Password>".htmlspecialchars($Password)."</Password>";
    			
    		}
    		if ($DupLogic!="")
    		{
    			$XML = $XML."<DupLogic>OR</DupLogic>";
    		}
    		else
    		{
    			$XML = $XML."<DupLogic>AND</DupLogic>";
    		}
    		
    		$XML = $XML."</Instructions>";
    	}
    	$Body = $Body."[Data]\n";
    	$XML = $XML."<accounts><account>";
    	$Phone = "";
    	$EA = "";
    	$WS = "";
    	$PR = "";
    	while(list($key,$value)= each($_POST)) 
    	{
    		eval("$\$key = \"$value\";");
    		
    		
    		{
    			
    			if ($key!="GMsubmit" && $key!="SMTP" && $key!="OnNewSendGMEmail" &&
    				$key!="OnDUPSendGMEmail" && $key!="OnNewAttachTrack" &&
    				$key!="OnDupAttachTrack" && $key!="SendToEmail" && $key!="DuplicateCount" && $key!="Word" &&
    				strpos($key, "DuplicateChecking") === false && $key!="OutPutAs" && $key!="DupLogic" && strpos($key, "pretty_") === false)
    				
    			{
    				
    				
    				if($value!="")
    				{
    					$Body = $Body.$key."=".$value."\n";
    					if (substr($key,0,5)!="PHONE" && substr($key,0,3)!="FAX" && substr($key, 0, 5)!="EMAIL" && substr($key,0, 7)!="WEBSITE")
          
    					{
    					
    						$PR = $PR."<property name=".chr(34).$key.chr(34)." db_name=".chr(34).$key.chr(34).">";
    						$PR = $PR."<property_string>".htmlspecialchars($value)."</property_string>";
    						$PR = $PR."</property>";
    					}
    					else
    					{
    						if(substr($key,0,5)=="PHONE")
    						{
    						
    						$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">";
    						$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>";
    						$Phone = $Phone."</phone>";
    						}
    						elseif(substr($key,0,3)=="FAX")
    						{
    						$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">";
    						$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>";
    						$Phone = $Phone."</phone>";
    						}
    						elseif(substr($key,0,7)=="WEBSITE")
    						{
    						$WS = $WS."<website primary=".chr(34)."1".chr(34)." id=".chr(34)."WS1".chr(34).">";
    						$WS = $WS."<properties><property name=".chr(34)."web_site".chr(34)."><property_string>".$value."</property_string></property></properties>";
    						$WS = $WS."</website>";
    						}
    						elseif(substr($key,0,5)=="EMAIL")
    						{
    						$EA = $EA."<email primary=".chr(34)."1".chr(34)." id=".chr(34)."EA1".chr(34).">";
    						$EA = $EA."<properties><property name=".chr(34)."email_address".chr(34)."><property_string>".$value."</property_string></property></properties>";
    						$EA = $EA."</email>";
    						}
    						
    					}
    				}	
    			
    			}
    		}
    		
    	}
    	if ($PR !="")
    	{$XML = $XML."<properties>".$PR."</properties>";}
    	if($Phone!="")
    	{
    	$XML = $XML."<phone_numbers>".$Phone."</phone_numbers>";
    	}
    	if($EA!="")
    	{
    	$XML = $XML."<emails>".$EA."</emails>";
    	}
    	if($WS!="")
    	{
    	$XML = $XML."<websites>".$WS."</websites>";
    	}
    	$XML = $XML."</account></accounts></gmdata>";
    	$ToSubject="Web Import";
    	
    	//The PHP built in function mail() will not raise or cause errors if it fails - so be sure that your PHP server is setup correctly!
    	if( $OutputAs!="INI")
    	{
    	$Body = $XML;
    	}
    	ini_set("SMTP", Decode($SMTP));
    	if(mail(Decode($SendToEmail), $ToSubject, $Body, "From: GoldMine WebImport <no-reply@frontrange.com>\r\nContent-Type: text/x-gm-impdata\r\n" )) {
    		
    	print "Your data has been recorded successfully!\n\n<!--\n".Decode($SendToEmail)."\n".$ToSubject."\n".$Body."\n\n".$OutputAs."\n\n-->";	
    	header('Location: index.php');
            exit();
    	}
    	else
    	{print("There was a mailer failure.\n\n<!--\n".$Body."\n\n-->");}
    }
    else
    {echo "There was no form data passed.";}	
    ?>
    </body>
    </html>
    PHP:
     
    Muhammad Haris, Aug 17, 2007 IP
  5. The_FNG

    The_FNG Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When I try that, I get the following...

    Warning: Cannot modify header information - headers already sent by (output started at /home/cust2/username/html/PHPMailer.php:8) in /home/cust2/username/html/phpmailer.php on line 299

     
    The_FNG, Aug 17, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Remove these lines from the top:
    
    <html>
    <head>
    <title>PHP Mail from GoldMine</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    Code (markup):
    So that there's no white space or anything infront the <?php tag.

    EDIT:

    And remove this line from near the bottom:
    
        print "Your data has been recorded successfully!\n\n<!--\n".Decode($SendToEmail)."\n".$ToSubject."\n".$Body."\n\n".$OutputAs."\n\n-->"; 
    
    PHP:
     
    nico_swd, Aug 17, 2007 IP
  7. The_FNG

    The_FNG Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Got it. Thank you very much for your assistance.
     
    The_FNG, Aug 17, 2007 IP
  8. Muhammad Haris

    Muhammad Haris Peon

    Messages:
    576
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Put those header lines back.

    At the top of the page use

    <?php ob_start(); ?>
    PHP:
     
    Muhammad Haris, Aug 17, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    There's no need. This page is just to send the email and redirect. There's no output needed at all.

    But if so, you'd need to add this at the bottom:
    
    <?php
    ob_end_flush();
    ?>
    
    PHP:
     
    nico_swd, Aug 17, 2007 IP
  10. Muhammad Haris

    Muhammad Haris Peon

    Messages:
    576
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #10
    But if he/she is validation whore like me and try to validate every page of his website. I would use the proper HTML heads.

    I think there is no need for ob_end_flush() because exit() does the job properly.
     
    Muhammad Haris, Aug 17, 2007 IP