Jump to content

How do I alter this code to display custom error pages?


jimbojones5678

Recommended Posts

Hi everyone,  :D

 

I am a beginner web designer and a novice php user. I am a regular forum user and understand that you should always do a search and try to find the answer yourself but I have done that and didn't get any results (or I didn't understand them!).

 

So I ask for some assistance - either you can tell me the code or link me to the correct answer.

 

I am working on a website that I have built a enquiry form for and it has a php script for it. I have managed to get the form running properly and got the reCaptcha working correctly (with a custom error page) but I do not understand how to add custom error pages for incomplete email addresses, empty email addresses, or for a blank form? I tried using the same tactic I used for the reCaptcha error page but it didn't work - probably because I was guessing and just tried it in a bunch of different places.

 

The error msg that displays now is just a plain white page with the msg - Email address is invalid appearing at the top left.

While this is suitably functional it doesn't really look like much so I want to build a custom page for each error that could happen.

 

So the code is below - if anyone can point a beginner in the right direction I would be super happy.  :mrgreen:

 

if you need anymore code or other details just tell me and I will post them up.

 

The url of the form page is http://www.sunsolutionshomeimprovement.com/onlinesales.html

 

This is the code I think you will need - I got it from a demo php script that I have modified. As I said I don't have much clue what I'm doing so I just posted it exactly how it looks - if I over did it I apologize... :oops:

 

68.// Validate email field.

69.

70.if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))

71.{

72.

73.if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or

74.a colon";}

75.

76.$_REQUEST['email'] = trim($_REQUEST['email']);

77.

78.if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

78.

79.)

80.

81.// Check referrer is from same site.

82.

83.if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

84.

85.// Check for a blank form.

86.

87.function recursive_array_check_blank($element_value)

88.(

89.

90.global $set;

91.

92.if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}

93.else

94.

95.

96.foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

97.

98.)

99.

100.)

101.

102.recursive_array_check_blank($_REQUEST);

103.

104.if(!$set){$errors[] = "You cannot send a blank form";}

105.

106.unset($set);

107.

108.// Display any errors and exit if errors exist.

109.

110.if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

111.

112.if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

113.

114.// Build message.

 

I don't think there is anymore that is relevant?

 

I just want to reiterate that I know nearly nothing about this stuff so if you could keep your answers simple it would help a lot - cheers!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.