Hello I am trying to make custom form and I can not get it to work correctly any help will be greatly appreciated here is the coding. the form is at: http://pixelgeek.net/temp2/quote.html PHP ------------------------------------------------------ <?php // Website Contact Form Generator // http://www.tele-pro.co.uk/scripts/contact_form/ // This script is free to use as long as you // retain the credit link // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "shawn@pixelgeek.net"; $Subject = Trim(stripslashes($_POST['Subject'])); $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Town = Trim(stripslashes($_POST['Town'])); $State = Trim(stripslashes($_POST['State'])); $Zipcode = Trim(stripslashes($_POST['Zipcode'])); $Vin_Number = Trim(stripslashes($_POST['Vin_Number'])); $Year = Trim(stripslashes($_POST['Year'])); $Make = Trim(stripslashes($_POST['Make'])); $Model = Trim(stripslashes($_POST['Model'])); $Body = Trim(stripslashes($_POST['Body'])); $Mileage = Trim(stripslashes($_POST['Mileage'])); $Interior_Color = Trim(stripslashes($_POST['Interior_Color'])); $Exterior_Color = Trim(stripslashes($_POST['Exterior_Color'])); $Doors = Trim(stripslashes($_POST['Doors'])); $Gears = Trim(stripslashes($_POST['Gears'])); $Condition = Trim(stripslashes($_POST['Condition'])); $Cylinders = Trim(stripslashes($_POST['Cylinders'])); $PWR_Windows = Trim(stripslashes($_POST['PWR_Windows'])); $Leather = Trim(stripslashes($_POST['Leather'])); $Diesel = Trim(stripslashes($_POST['Diesel'])); $PWR_Doors = Trim(stripslashes($_POST['PWR_Doors'])); $Quad_Cab = Trim(stripslashes($_POST['Quad_Cab'])); $4x4 = Trim(stripslashes($_POST['4x4'])); $Sunroof = Trim(stripslashes($_POST['Sunroof'])); $T-Tops = Trim(stripslashes($_POST['T-Tops'])); $Dully = Trim(stripslashes($_POST['Dully'])); $Air-Conditioning = Trim(stripslashes($_POST['Air-Conditioning'])); $Extended_Cab = Trim(stripslashes($_POST['Extended_Cab'])); $Turbo = Trim(stripslashes($_POST['Turbo'])); $Owe_Money = Trim(stripslashes($_POST['Owe_Money'])); $Amount_Owed = Trim(stripslashes($_POST['Amount_Owed'])); $Asking_Price = Trim(stripslashes($_POST['Asking_Price'])); $Comment = Trim(stripslashes($_POST['Comment'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Town: "; $Body .= $Town; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Zipcode: "; $Body .= $Zipcode; $Body .= "\n"; $Body .= "Vin_Number: "; $Body .= $Vin_Number; $Body .= "\n"; $Body .= "Year: "; $Body .= $Year; $Body .= "\n"; $Body .= "Make: "; $Body .= $Make; $Body .= "\n"; $Body .= "Model: "; $Body .= $Model; $Body .= "\n"; $Body .= "Body: "; $Body .= $Body; $Body .= "\n"; $Body .= "Mileage: "; $Body .= $Mileage; $Body .= "\n"; $Body .= "Interior_Color: "; $Body .= $Interior_Color; $Body .= "\n"; $Body .= "Exterior_Color: "; $Body .= $Exterior_Color; $Body .= "\n"; $Body .= "Doors: "; $Body .= $Doors; $Body .= "\n"; $Body .= "Gears: "; $Body .= $Gears; $Body .= "\n"; $Body .= "Condition: "; $Body .= $Condition; $Body .= "\n"; $Body .= "Cylinders: "; $Body .= $Cylinders; $Body .= "\n"; $Body .= "PWR_Windows: "; $Body .= $PWR_Windows; $Body .= "\n"; $Body .= "Leather: "; $Body .= $Leather; $Body .= "\n"; $Body .= "Diesel: "; $Body .= $Diesel; $Body .= "\n"; $Body .= "PWR_Doors: "; $Body .= $PWR_Doors; $Body .= "\n"; $Body .= "Quad_Cab: "; $Body .= $Quad_Cab; $Body .= "\n"; $Body .= "4x4: "; $Body .= $4x4; $Body .= "\n"; $Body .= "Sunroof: "; $Body .= $Sunroof; $Body .= "\n"; $Body .= "T-Tops: "; $Body .= $T-Tops; $Body .= "\n"; $Body .= "Dully: "; $Body .= $Dully; $Body .= "\n"; $Body .= "Air-Conditioning: "; $Body .= $Air-Conditioning; $Body .= "\n"; $Body .= "Extended_Cab: "; $Body .= $Extended_Cab; $Body .= "\n"; $Body .= "Turbo: "; $Body .= $Turbo; $Body .= "\n"; $Body .= "Owe_Money: "; $Body .= $Owe_Money; $Body .= "\n"; $Body .= "Amount_Owed: "; $Body .= $Amount_Owed; $Body .= "\n"; $Body .= "Asking_Price: "; $Body .= $Asking_Price; $Body .= "\n"; $Body .= "Comment: "; $Body .= $Comment; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?>
I do not understand what I need to change? Thanks for your reply but could you go into a little more detail.
php variable starts with $ right? but not number after so. $4x4 is not valid, rename it something like $_4x4 or any...
I changed $4x4 to $Drive_4x4 and all other references but still no luck. When I test form at http://pixelgeek.net/temp2/quote.html it takes me to a blank page http://pixelgeek.net/temp2/quote.php I do not understand I am using a similar script for the contact page at http://pixelgeek.net/temp2/contact.html and it works just fine. Do you think you could test it so you can see what I mean Thanks for your continued help
I went overkill for what you wanted, but I figure this would help others. It has not been tested and there are some better ways of achieving faster processing and such, but I wasn't too concerned about it. Hope this helps! <?php // ---------------------------------------------------------------- // A Better "Website Contact Form" // Written by: Trikun3 // URI: http://trikun3.com/ // ---------------------------------------------------------------- // Some application defaults. $post_array = array(); $Body = ''; // Configuration Variables. $EmailTo = 'YOUR_EMAIL@HERE.COM'; $Subject = 'YOUR_SUBJECT_HERE'; // Set all of the post data you want to retrieve. $retrieve = 'EmailFrom,Subject,Name,Tel,Town,State,Zipcode,Vin_Number,Year,Make,Model,Body,Mileage,Interior_Color,Exterior_Color,Doors,Gears,Condition,Cylinders,PWR_Windows,Leather,Diesel,PWR_Doors,Quad_Cab,4x4,Sunroof,T-Tops,Dully,Air-Conditioning,Extended_Cab,Turbo,Owe_Money,Amount_Owed,Asking_Price,Comment'; // ---------------------------------------------------------------- // Functions. function sanitize($input) { $safe = filter_input(INPUT_POST, $input, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH); return $safe; } // ---------------------------------------------------------------- // Set the explode(array) into $items. $items = explode(',', $retrieve); // Foreach post data element, assign it into the post_array with the sanitized value. foreach($items as $item) { $post_array[$item] = sanitize($item); } // Check that EmailFrom exists. if(isset($EmailFrom) AND !empty($EmailFrom)) { header('Location: error.htm'); exit(); } // Generate the body with the post_array. foreach($post_array as $name => $value) { $Body .= "{$name}: $value\n"; } // Success or Failure redirection. // If the email was sent: if(mail($EmailTo, $Subject, $Body, "From: <{$EmailFrom}>")) { header('Location: ok.htm'); exit(); } else { header('Location: error.htm'); exit(); } /* END OF FILE */ PHP:
@Trikun3 You don't need: // Foreach post data element, assign it into the post_array with the sanitized value. foreach($items as $item) { $post_array[$item] = sanitize($item); } PHP: As this can simply be achieved with: $post_array = array_map('sanitize', $items); PHP: But overall your codes neat
Surprising, but the point whether to use foreach or array_map in this case is arguable, faster code vs minimal code.
Bit off topic but have to ask Isn´t faster always better than minimal? Personally I rather have a fast website than one that´s "Small" in code size..