66 replies [Last post]
Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I recently worked on a job in which I produced the HTML and CSS and another (more experienced) developer produced the needed PHP forms. I just had to add his PHP forms to my pile of files, and tweak where necessary to allow them all to work nicely together. This was a challenge, as I'm new to PHP. With the other developer's help, it was successful and the job was completed.

Seeing as I'd like to add a PHP-based "contact me" form to my own site, I asked his permission to use his code to take apart and play with. He kindly obliged. I noticed that his PHP was all using tables instead of CSS. I'd very much like to avoid using tables for the purposes of visual structure (or anything other than displaying tabular information, as I've learned here).

I've pulled apart the code and looked at the scripting on some other sites where people use PHP with CSS, hoping to pick through it and figure out my coding puzzle. Hoo boy! This is a challenge to say the least. I'm feeling a bit like a mentally challenged kid with a Rubik's cube. This task is a bit daunting, as I feel like I'm slightly out of my league ~ although I've learned that stepping out of one's comfort zone is the only way to move up to that next league.

Could I ask for some help? I'm sure you'll look at some of the code and think, "Why in the world has she got THAT put THERE?!" and I honestly won't be able to give you a good answer. Any help or suggestions would be very much appreciated, as this is my first stab at PHP although I admit much of it is copied and pasted. Please excuse my ignorance in this field! As always, I'm hoping to learn.

Here's my site:
http://www.digitalpawprint.com
(my old, untouched, PHP-free contact page is sitting in the contact section.)
The page I'm working on: http://www.digitalpawprint.com/contact/contact_test.php
My CSS page:
http://www.digitalpawprint.com/woof.css

Tags:
amadika
amadika's picture
Offline
Enthusiast
Texas
Last seen: 12 years 13 weeks ago
Texas
Timezone: GMT-6
Joined: 2007-04-16
Posts: 206
Points: 4

I've done work with php and

I've done work with php and have a php contact page on my own site. I'm not sure exactly what you want, but I do notice right away, that you have used an id twice on your input fields, which is a no-no!!

As php is a server-side script, it might be worth posting your actual code... so we can look at it.

@}->-- Amanda

amadika
amadika's picture
Offline
Enthusiast
Texas
Last seen: 12 years 13 weeks ago
Texas
Timezone: GMT-6
Joined: 2007-04-16
Posts: 206
Points: 4

Just a side note... I don't

Just a side note... I don't know if you've ever noticed the annoying dotted lines that appear when you are doing an image replacement and using a negative text indent (shows up in firefox) but here is a link that talks about how to fix it.
http://www.last-child.com/get-rid-of-the-dotted-lines-on-links-with-image-replacement/
The suggestion at the bottom (using overflow: hidden) works does work in a lot of cases.

@}->-- Amanda

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Lamb not to sure here what

Lamb not to sure here what you are actually wanting help with? what is your "coding puzzle"?

This is one instance where the reverse of our usual retort is true when presented with server side script, we do need to see the script rather than server output, i.e the final page delivered.

It will help to see how the script is handling the html generation.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 7 years 32 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

I'd have thought that in

I'd have thought that in most cases the PHP that handles the form processing and the HTML of the form itself would be completely separate so your only issue would be how the data is handled by the script after the form's submitted.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Its not quite completely

Its not quite completely separate, at least not how most people seem to think of it. But Tyssen is basically correct.

(1) Code up your HTML page with everything. ie
- all form elements
- all error message possibilities
- all different responses

(2) Check through all of the above with mock data. Use javascript if javascript will be used in the final form. But there is no need to mess with php yet.

(3) Now your form and all its possible responses are set you can attach it to a PHP file and replace those parts of your page which will get their values from the server with PHP statements.

There was another thread not so long ago (last two weeks??) which discussed this as well. Search back and that should provide some help. Iirc there were some code examples in the thread.

thepineapplehead
thepineapplehead's picture
Offline
Moderator
Last seen: 4 weeks 3 days ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9683
Points: 819

Ello again Lamb

Ello again Lamb Wink

Verschwindende wrote:
  • CSS doesn't make pies

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Back in the security of the forum... ahhhhh.

Amadika, thank you for both of your posts ~ I fixed both things that you suggested. That was much appreciated!

Hugo and Tyssen ~ my smarty mentors. Am I ever glad to see you! When I attempt a test (fill in the info and hit "send"), I get a "the webpage cannot be found" so I know that something somewhere in my script is incorrect and the message is not being sent and the "thank you" page is not appearing. In the meantime I'm continuing to toy with this in hopes of figuring it out. Sorry I forgot the obvious that the commented out scripting doesn't show in "view source" ~ ha. I'm going to try to resolve this first with all of your advice, then will properly post my code on my next post if I can't seem to get it right. Tyssen, I think I follow what you're saying. It took me a read or two to get it through my thick noggin, but I think I'm with you.

Chris S. ~ thank you for adding to and clarifying with such detail what Tyssen was saying. I'm going to attempt to put your advice into action now.

Pineapplehead ~ what would I do without this forum and its kind and generous participants? I'd most likely be bashing my head into my keyboard. I've been away far too long, it's nice to be back feeding my brain.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Okay I'm stumped... *sigh* ...here's the code.

*sidenote: I just found ClevaTreva and Hugo's multiple posts to someone else's questions about something very similar, as was suggested to me. (I'm pretty sure this is the one) and I'm currently pouring over it. In the meantime, here's my code as it presently stands:

<?php

/*
========================================================================
-- function WriteTXTFile($filenm, $InputStr) --
Function to write out information to an existing text file. Function
opens existing file, reads in it's content and then concatenates new
string to existing content and re-writes to file.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
$InputStr - string to be concatenated to existing file content and
written to the file.
------------------------------------------------------------------------
Output:
- None -
========================================================================
*/
function WriteTXTFile($filenm, $InputStr){
$content = ReadTXTFile($filenm);
$content .= $InputStr;
$fileh = fopen($filenm, 'w') or die("Can't open file");
fwrite($fileh, $content);
fclose($fileh);
}

/*
========================================================================
-- function ReadTXTFile($filename) --
Function to read information from an existing text file. Function opens
an existing file, reads the entire content and returns the content.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
------------------------------------------------------------------------
Output:
return - string content of all existing content within the file
========================================================================
*/
function ReadTXTFile($filename) {
$fh = fopen($filename, 'r');
$theData = fread($fh, filesize($filename));
fclose($fh);
return $theData;
}

/*
========================================================================
-- function is_email($Addr) --
Function to validate correct email format. Uses regualr expression
matching
------------------------------------------------------------------------
Input:
$Addr - string email address
------------------------------------------------------------------------
Output:
return - boolean
========================================================================
*/
function is_email($Addr)
{
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum)$/ix';
return preg_match($p, $Addr);
}

//Variables - Names are self explainitory, set each one with post variables. Will be empty on first load
$Yourname = $_REQUEST['Yourname'] ;
$Companyname = $_REQUEST['Companyname'] ;
$Email = $_REQUEST['Email'] ;
$Url = $_REQUEST['Url'] ;
$Whassup = $_REQUEST['Whassup'] ;
//message variable to return error message
$FormMessage = '';
//meta tag variable to control successful redirect
$metaRef = '';
$ThankFlag = '';

//log entry variable used to build the string to be stored in reglog.txt
$LogEntry = $Yourname."\t".$Companyname."\t".$Email."\t".$Url."\t".Whassup;

//message variable for content that will be sent in text email
$message = "Digital Paw Print web contact\n";
$message .= "Yourname: ".$Yourname."\n";
$message .= "Companyname: ".$Companyname."\n";
$message .= "Email:\t".$Email."\n";
$message .= "Url:\t".$Url."\n";
$message .= "Whassup:\t".$Whassup."\n";

if (!isset($_REQUEST['Email'])) {
//"Rough" check to see if first visit to page. Set welcome message
$FormMessage = 'Please complete all fields that are not marked with "optional".';
}
elseif (empty($Yourname) || empty($Companyname) || empty($Email)|| empty($Url) || empty($Whassup)) {
//check to see if all manditory fields have content. If fails, send error message
$FormMessage = 'Sorry, you must complete all the manditory fields.
Please see fields that are NOT marked as "optional"..';
}
elseif(!is_email($Email)) {
//check to see if email address is valid. If fails, send error message
$FormMessage = 'Please enter a valid e-mail address';
}
else {
//Write out successful entry to log file
//WriteTXTFile("contactlog.txt", $LogEntry);
//Send email to client
//[email protected]
mail("[email protected]", $message, "From: $Email" );
//set redirect to thank you page with appropriate "info" parameter value. Added to HTML section
//$metaRef = '"';

//NOTE: Commented out header() function as failed with output error
//header( "location: ./contact/ThankYou.php" );
$FormMessage = 'Thank you, your contact request has been sent.';
$ThankFlag = 'true';
}
?>

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

The failure to send should

Edit: x-posted with your posted code so ignore last paragraph
The failure to send should be a semi trivial matter to correct, sounds simply like an incorrect path somewhere.

The comments so far suggest to my mind that this is an all in one script so to speak; that is, all the necessary scripting, html form generation, and then processing and forwarding of the user input is handled from within the same page, which if one is not familiar with PHP(or any scripting ) can be confusing as many actions tend to loop around and through the same page making it difficult to follow the script flow, naturally I may be wide of the mark here!

With PHP at a basic level there tend to be two approaches one can take to the marriage of the script and the HTML

On the one hand one can write lots of complicated script and interspersed within that are print or echo commands to write strings containing snippets of html to be outputed

On the other the script can do it's work (at say the top of the page) then be closed out and html written in the normal fashion within that html then are php variables that will include necessary values required, this is the cleaner method and easier imo to understand and work with,

Of course that is a simplified take on the subject Smile

It would help us all understand what your working with if you posted the main script you can even wrap it in <?php><?> code tags for lovely highlighted colors.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

So your form action is

So your form action is sending to this file? and this file is responsible for outputting a success page albeit dubious html Smile

Hmm, I'm not getting how this works really the script as shown is generating message variables but I don't see where or how they are meant to be displayed with the original form. We seem to have a 'if is not set email then generate error' and a comment about this being a first visit to page check :? but this isn't the page is it?

I see error messages for form failure but no method of returning to the form or for preserving what the user may have already entered. er perhaps that's the commented out header location?

I also have mild reservations as to how some of this script is written, why $_REQUEST is used allowing three possible means of entering data to the variables, but I'll hold of commenting further as Chris will cast a more expert eye over things than I can.

My approach is different to this in that I use variables to populate the form input values that way I can return an error message in them or if they pass checks but others fail the correct ones are returned so the user doesn't have to re-type the info, I also keep the whole workings in the one file until the checks are passed and data passed on .

Lamb can you show us the form page as well? and the ThankYou.php file

Is the thread you found and are reading this one?

http://csscreator.com/node/20077

In which case it might be worth while considering 'borrowing Cleva Trevas example and working with that? I'm sure he'd be more than happy for you to and he has put fair amount of work into ensuring it's safe and secure and that it works around 'nice' markup and in a templated fashion.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Isn't <FONT> pretty well

Isn't <FONT> pretty well obsolete. Why not use a class and CSS?

Rather than open for writing, why not open for append?

My personal style is to keep HTML out of the working PHP as much as possible. I would not put HTML into messages as the code goes along but set a flag and save the message text. Then when the page is output embed php echos in the HTML to output your text. And use small "helper" functions to translate flags into things like class names and checkbox/radio button states.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Somehow I don't think <FONT>

Somehow I don't think <FONT> is lambs choice it smacks of what so many scripters still seem to consider passes for markup.

The error messages should just be text strings it's how I deal with things and output them along with generally an if/else setting another variable to output a class name or not as the case may be.

I do think we could do with seeing the rest of the files.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

One comment. Don't make all

One comment.

Don't make all your error checking if ... else if ... else if ... else

If there is a bad email and the company name is missing, you need to output two messages so the user can correct both. Its not so good to output one, have them fix the email, then to fail again and ask for the company.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

You're absolutely right,

You're absolutely right, Hugo ~ the "font" reference (as well as many other things) are not my choice... I'm trying to alter someone else's script from tables-only to CSS, and that's just one part I haven't yet dealt with.

Incidentally, the original author had *'s after all mandatory fields... if the user didn't fill in a mandatory field, you recieved an error message. I'd like to avoid the *'s and just have "(optional)" after the name of each optional field... so I'd like it to work so that you receive a little error message if you didn't fill in a field that didn't have "(optional)" next to it. I'm guessing that this must certainly be possible, and I just have to find my way to it in time, with a little help from my friends.

I'm also a big fan of reducing as much unnecessary code as possible (which I'm sure both you and Chris S. are as well), so if you see anything that could be simplified somehow, I'm all ears.

Sorry I keep on not giving you all necessary code... I guess it's obvious that I'm still a bit green as to what makes PHP tick and what you need to sort it out. As someone with a much stronger creative side to the brain than a technical side, do understand that I often need to read and reread people's explanations and then beat them soundly into my head. Once it's in there, I'm fine. It's just wrapping my head around it that seems to be the trying part. Regardless, I take great pride in my albeit slightly stunted techie-side. Smile

All right... here's what I've got:

The main php page which has both html and php:

<?php

/* TODO: Add code here */
/*
========================================================================
-- function WriteTXTFile($filenm, $InputStr) --
Function to write out information to an existing text file. Function
opens existing file, reads in it's content and then concatenates new
string to existing content and re-writes to file.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
$InputStr - string to be concatenated to existing file content and
written to the file.
------------------------------------------------------------------------
Output:
- None -
========================================================================
*/
function WriteTXTFile($filenm, $InputStr){
$content = ReadTXTFile($filenm);
$content .= $InputStr;
$fileh = fopen($filenm, 'w') or die("Can't open file");
fwrite($fileh, $content);
fclose($fileh);
}

/*
========================================================================
-- function ReadTXTFile($filename) --
Function to read information from an existing text file. Function opens
an existing file, reads the entire content and returns the content.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
------------------------------------------------------------------------
Output:
return - string content of all existing content within the file
========================================================================
*/
function ReadTXTFile($filename) {
$fh = fopen($filename, 'r');
$theData = fread($fh, filesize($filename));
fclose($fh);
return $theData;
}

/*
========================================================================
-- function is_email($Addr) --
Function to validate correct email format. Uses regualr expression
matching
------------------------------------------------------------------------
Input:
$Addr - string email address
------------------------------------------------------------------------
Output:
return - boolean
========================================================================
*/
function is_email($Addr)
{
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum)$/ix';
return preg_match($p, $Addr);
}

//Variables - Names are self explainitory, set each one with post variables. Will be empty on first load
$Yourname = $_REQUEST['Yourname'] ;
$Companyname = $_REQUEST['Companyname'] ;
$Email = $_REQUEST['Email'] ;
$Url = $_REQUEST['Url'] ;
$Whassup = $_REQUEST['Whassup'] ;
//message variable to return error message
$FormMessage = '';
//meta tag variable to control successful redirect
$metaRef = '';
$ThankFlag = '';

//log entry variable used to build the string to be stored in reglog.txt
$LogEntry = $Yourname."\t".$Companyname."\t".$Email."\t".$Url."\t".Whassup;

//message variable for content that will be sent in text email
$message = "Digital Paw Print web contact\n";
$message .= "Yourname: ".$Yourname."\n";
$message .= "Companyname: ".$Companyname."\n";
$message .= "Email:\t".$Email."\n";
$message .= "Url:\t".$Url."\n";
$message .= "Whassup:\t".$Whassup."\n";

if (!isset($_REQUEST['Email'])) {
//"Rough" check to see if first visit to page. Set welcome message
$FormMessage = 'Please complete all fields that are not marked with "optional".';
}
elseif (empty($Yourname) || empty($Companyname) || empty($Email)|| empty($Url) || empty($Whassup)) {
//check to see if all manditory fields have content. If fails, send error message
$FormMessage = 'Sorry, you must complete all the manditory fields.
Please see fields that are NOT marked as "optional"..';
}
elseif(!is_email($Email)) {
//check to see if email address is valid. If fails, send error message
$FormMessage = 'Please enter a valid e-mail address';
}
else {
//Write out successful entry to log file
//WriteTXTFile("contactlog.txt", $LogEntry);
//Send email to client
//[email protected]
mail("[email protected]", $message, "From: $Email" );
//set redirect to thank you page with appropriate "info" parameter value. Added to HTML section
//$metaRef = '"';

//NOTE: Commented out header() function as failed with output error
//header( "location: ./contact/ThankYou.php" );
$FormMessage = 'Thank you, your contact request has been sent.';
$ThankFlag = 'true';
}
?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Contact Us

Why not? You've got nothing to lose. Estimates are free. And besides, we're not one of those annoying companies that will bug you incessantly once we have your e-mail address. We also don't give your info out to anyone else.

Wanna talk? Ask us a question? Go for it. We'll tell you what you want to know, then move on as you see fit.

Your name:

Company name (optional):

E-mail:

URL (optional):

Whassup?

The small bit of related css I've added to my css page:
(you can see the whole css page at http://www.digitalpawprint.com/woof.css

.send { float: right; padding: 2px; }

The page called "contactlog.txt":

Yourname Companyname Email Url Whassup

And the page called "thankyou.php":

<?php

/* TODO: Add code here */
$FormMessage = $_REQUEST['info'] ;
if (!isset($_REQUEST['info'])) {
$FormMessage = 'Thank you, your message has been sent.';
}
elseif (empty($FormMessage)) {
$FormMessage = 'Thank you, your message has been sent.';
}
else {
$FormMessage = 'Thank you, your message has been sent.';
}

?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Thank you

<?php echo $FormMessage ?>

That's about it! I'm now due to take my pooch out for a walk, and upon return will read over your last comments again to better absorb them. Thanks again for all of your help!!!

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 7 years 32 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

My comments:

My comments:

  1. Same comment Hugo made about using $_POST instead of $_REQUEST for getting the form values.
  2. The two functions for reading and writing a text file don't actually seem to be called anywhere and I don't really think they're necessary.
  3. The form action for the contact page is /thankyou/ but the page that processes the email is the one you're currently on, in other words a self-referencing form, so I think your form action wants to be something like <?php $_SERVER['php self'] ?>. If the form is submitted succesfully, you'll then want a PHP redirect to send you to thankyou.php although I generally just set up an if else statement and return the message to the same page, something like this:

    <? if(!isset($_GET['email'])) { ?>

    This is the default message on your contact page before the form is submitted. The message above checks to see if a querystring has been set (coming back from the script after it's been processed. If it hasn't, then display default message.

    <? displayForm(); // a function to call the HTML of the form } else { if ($_GET['email'] == "thanks") { ?>

    Thank you your message has been received.

    } }?>

  4. If you do decide to use a separate thankyou.php, there's no need to wrap your script output in a form (in fact, it's invalid HTML) because the content doesn't contain any form controls, it's just text.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

that'll be

that'll be $_SERVER['PHP_SELF'].

The advantage of redirecting to a thank you page is the back button will take you back to the form without the browser asking you to confirm the post. Its a sensible to redirect after successful processing of any form submitted using post for that reason. It also helps reduce the possibility of a double post if the user hits refresh.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

I just new that having

Laughing out loud I just new that having decided to have a deeper look by the time I got around to posting ........

There are a number of vital errors in this script that cause absolute failure your form input names do not match your $_POST['names'] or as they are at present $_REQUEST you have different names and where they are the same you have 'case' mismatches; the script used things like 'Email' you used in the form 'email'

The form action has been mentioned.

The redirect does not work as you have a 'header already outputted' error the mail("[email protected] line before the header redirect is sending headers

However you don't in fact need the redirect as there is a success message variable waiting to print out in that block, although Chris's point about always redirecting ought to be noted.

The other problem is that you aren't actually echoing any of those messages if you place:
<?php print $FormMessage ?>

just before the form or somewhere suitable then you will see these messages.

Personally I would deal with them differently at a basic level change them just to strings in the script $FormMessage = 'message text here'; and
<p><?php print $Formmessage ?></p>

There are better ways of doing most of this though, and I have a problem with the check on all of the submits together and failing all based on only one possibly being empty

I take an approach that checks each cleans it then sets it in a variable that I can use to populate the value attribute of the inputs so that if one is wrong the correct ones are not lost but retained saving re-typing, too tired to explain that better but if the thread is still running tomorrow I'll try and show what I do with the submitted values.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

oooh fun it's just like

oooh fun it's just like Christmas ~ I've got all these fun new coding bits to play with and try out. I suppose it's morning over where you guys are (U.K. & down under if I recall correctly?) but it's evening here and much to my chagrin I have to leave my computer until morning due to other plans. I'll try out your suggestions and will report back with my findings.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Okay I take that back. It

Okay I take that back. It doesn't feel quite like Christmas. After reading through everyone's comments again, I started to make a few adjustments here and there but seeing as I didn't really know what I was doing, thought it might be best to start over somewhat with ClevaTreva's example. I must be still missing a lot of things, though, as it doesn't appear to be anything close to working. I was a bit unsure about what to adjust in CT's sample... like this, a line from enquire.php:

if (isset($_POST['submitme'])) $submit=addslashes(htmlspecialchars(strip_tags(trim($_POST['submit']))));

I feel like a bit of a dumbbutt asking this, but what do I put in the "addslashes(htmlspecialchars(strip_tags(trim" part? I guess some uh... slashes... and uh... *swallowing hard* ... other stuff? Sick

So there's that, and then the main issue I believe is that I might not have the files in the right spot. Here's what I've put where:
1) enquire.php is sitting at the main root level along with index.html and woof.css
2) enquireform.inc.php and mail1.inc.php and mail2.inc.php are all sitting IN the "contact" folder... this folder which sits at root level. I suspect this is where I'm getting mixed up somehow... I need the files to sit where they are, but they obviously must be able to find one another in their respective spots, and I think I haven't gotten this resolved despite my hunting and pecking.

Am I getting there, or getting into a bigger mess?

You can see the form at http://www.digitalpawprint.com/contact/enquireform.inc.php ~ things are not lined up as I would like, but I think this is the least of my concerns until I get things working.

Here's my code:
enquire.php (sitting at root level):
<?php
// put your web address instead of the blahblah's in this document!

$enquire_dir="http://www.digitalpawprint.com";

// Read the post variables, strip out hacking code, set internal form variables
if (isset($_POST['submitme'])) $submit=addslashes(htmlspecialchars(strip_tags(trim($_POST['submit']))));
if (isset($_POST['namefrom'])) $namefrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['namefrom']))));
if (isset($_POST['businessfrom'])) $businessfrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['businessfrom']))));
if (isset($_POST['emailfrom'])) $emailfrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['emailfrom']))));
if (isset($_POST['comments'])) $comments=addslashes(htmlspecialchars(strip_tags(trim($_POST['comments']))));

if (!isset($_POST['submitme'])):
//This html is the actual form
include ("./contact/mail1.inc.php");
include ("./contact/enquireform.inc.php");
include ("./contact/mail2.inc.php");
//end of actual form html

else:

/* error function */

function error($msg) {
global $namefrom,$businessfrom,$emailfrom,$comments,$enquire_dir;
include ("enquire/mail1.inc.php");
echo $msg;
include ("./contact/enquireform.inc.php");
include ("./contact/mail2.inc.php");
exit;
}

/* Check for blanks start */
// these 4 lines check for blanks and display an error if they are found. You will need to add or remove items
// from this block to add or remove required fields, please follow the format already laid out.

if ($namefrom=="" or $emailfrom=="" or $businessfrom=="" or $comments=="") {
error("

Not Sent: One or more required fields were left blank.

The fields marked in red must be completed.

Please fill them in and re-submit.

");
}
/* check for blank end */

//email blocker start - to block from emails. add more as shown with x's
if ($emailfrom=="[email protected]" or $emailfrom=="[email protected]"){
error("

Not Sent: You are not authorised.

xxxxxxxxxxx

");
}
//end

//ip address blocker start - simply add more as sshown with x's to expand
if ($_SERVER["REMOTE_ADDR"]=="10.10.10.10"){
error("

Not Sent: You are not authorised.

xxxxxxxxxxx

");
}
//end

/* email validation start - checks correct eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6e%61%6d%65%40%68%6f%73%74%2e%65%78%74%22%3e%6e%61%6d%65%40%68%6f%73%74%2e%65%78%74%3c%2f%61%3e%27%29%3b')) form*/
// if you do not wish to use email validation or email is not a required field (above),
// comment out the following 4 code lines by adding a // at the beginning as has been
// done here.

if ((!ereg(".+\@.+\..+", $emailfrom)) || (!ereg("^[[email protected]]+$", $emailfrom))) {
error("

Not Sent: Invalid email address.

Please correct this and try again.

");
}

/* email validation end */

//finally, send our email and show confirmation. I have commented this out, you need to remove the slash star
//and star slash, fill in the details and text on a real server!

/*
$body="The following enquiry was made via the digitalpawprint.com website:\n\nThe contact's details are as follows:\n\n$namefrom\n$message\nIP Logged: $REMOTE_ADDR\n\n";
mail("The email address you want the enquiry to go to here", "digitalpawprint.com Website Enquiry", $body, "From: $namefrom <$emailfrom\n");
mail($emailfrom, "digitalpawprint.com Website Enquiry", "Thankyou for your enquiry.\n\nWe will contact you shortly.\n\n\n\n\n\n\nYour Customer Service Rep's Name\nYour Company Name\n\n(This is an automated response to your enquiry at wwww.digitalpawprint.com)", "From: Digital Paw Print
enquireform.inc.php (sitting in the contact folder):

<?php

/* TODO: Add code here */
/*
========================================================================
-- function WriteTXTFile($filenm, $InputStr) --
Function to write out information to an existing text file. Function
opens existing file, reads in it's content and then concatenates new
string to existing content and re-writes to file.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
$InputStr - string to be concatenated to existing file content and
written to the file.
------------------------------------------------------------------------
Output:
- None -
========================================================================
*/
function WriteTXTFile($filenm, $InputStr){
$content = ReadTXTFile($filenm);
$content .= $InputStr;
$fileh = fopen($filenm, 'w') or die("Can't open file");
fwrite($fileh, $content);
fclose($fileh);
}

/*
========================================================================
-- function ReadTXTFile($filename) --
Function to read information from an existing text file. Function opens
an existing file, reads the entire content and returns the content.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
------------------------------------------------------------------------
Output:
return - string content of all existing content within the file
========================================================================
*/
function ReadTXTFile($filename) {
$fh = fopen($filename, 'r');
$theData = fread($fh, filesize($filename));
fclose($fh);
return $theData;
}

/*
========================================================================
-- function is_Email($Addr) --
Function to validate correct email format. Uses regualr expression
matching
------------------------------------------------------------------------
Input:
$Addr - string email address
------------------------------------------------------------------------
Output:
return - boolean
========================================================================
*/
function is_Email($Addr)
{
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum)$/ix';
return preg_match($p, $Addr);
}

//Variables - Names are self explainitory, set each one with post variables. Will be empty on first load
$Yourname = $_POST['Yourname'] ;
$Companyname = $_POST['Companyname'] ;
$Email = $_POST['Email'] ;
$Url = $_POST['Url'] ;
$Whassup = $_POST['Whassup'] ;
//message variable to return error message
$FormMessage = '';
//meta tag variable to control successful redirect
$metaRef = '';
$ThankFlag = '';

//log entry variable used to build the string to be stored in reglog.txt
$LogEntry = $Yourname."\t".$Companyname."\t".$Email."\t".$Url."\t".Whassup;

//message variable for content that will be sent in text email
$message = "Digital Paw Print web contact\n";
$message .= "Yourname: ".$Yourname."\n";
$message .= "Companyname: ".$Companyname."\n";
$message .= "Email:\t".$Email."\n";
$message .= "Url:\t".$Url."\n";
$message .= "Whassup:\t".$Whassup."\n";

if (!isset($_POST['Email'])) {
//"Rough" check to see if first visit to page. Set welcome message
$FormMessage = 'Please complete all fields that are not marked with "optional".';
}
elseif (empty($Yourname) || empty($Companyname) || empty($Email)|| empty($Url) || empty($Whassup)) {
//check to see if all manditory fields have content. If fails, send error message
$FormMessage = 'Sorry, you must complete all the manditory fields.
Please see fields that are NOT marked as "optional"..';
}
elseif(!is_Email($Email)) {
//check to see if email address is valid. If fails, send error message
$FormMessage = 'Please enter a valid e-mail address';
}
else {
//Write out successful entry to log file
//WriteTXTFile("contactlog.txt", $LogEntry);
//Send email to client
//[email protected]
mail("[email protected]", $message, "From: $Email" );
//set redirect to thank you page with appropriate "info" parameter value. Added to HTML section
//$metaRef = '"';

//NOTE: Commented out header() function as failed with output error
//header( "location: ./contact/ThankYou.php" );
$FormMessage = 'Thank you, your contact request has been sent.';
$ThankFlag = 'true';
}
?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Contact Us

Why not? You've got nothing to lose. Estimates are free. And besides, we're not one of those annoying companies that will bug you incessantly once we have your e-mail address. We also don't give your info out to anyone else.

Wanna talk? Ask us a question? Go for it. We'll tell you what you want to know, then move on as you see fit.

./enquire.php">

Enquiry Form Your Name: " /> Business Name: " /> Your Email Address: " /> Comments: <?php echo $comments;?>

<?php

/* TODO: Add code here */
/*
========================================================================
-- function WriteTXTFile($filenm, $InputStr) --
Function to write out information to an existing text file. Function
opens existing file, reads in it's content and then concatenates new
string to existing content and re-writes to file.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
$InputStr - string to be concatenated to existing file content and
written to the file.
------------------------------------------------------------------------
Output:
- None -
========================================================================
*/
function WriteTXTFile($filenm, $InputStr){
$content = ReadTXTFile($filenm);
$content .= $InputStr;
$fileh = fopen($filenm, 'w') or die("Can't open file");
fwrite($fileh, $content);
fclose($fileh);
}

/*
========================================================================
-- function ReadTXTFile($filename) --
Function to read information from an existing text file. Function opens
an existing file, reads the entire content and returns the content.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
------------------------------------------------------------------------
Output:
return - string content of all existing content within the file
========================================================================
*/
function ReadTXTFile($filename) {
$fh = fopen($filename, 'r');
$theData = fread($fh, filesize($filename));
fclose($fh);
return $theData;
}

/*
========================================================================
-- function is_Email($Addr) --
Function to validate correct email format. Uses regualr expression
matching
------------------------------------------------------------------------
Input:
$Addr - string email address
------------------------------------------------------------------------
Output:
return - boolean
========================================================================
*/
function is_Email($Addr)
{
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum)$/ix';
return preg_match($p, $Addr);
}

//Variables - Names are self explainitory, set each one with post variables. Will be empty on first load
$Yourname = $_POST['Yourname'] ;
$Companyname = $_POST['Companyname'] ;
$Email = $_POST['Email'] ;
$Url = $_POST['Url'] ;
$Whassup = $_POST['Whassup'] ;
//message variable to return error message
$FormMessage = '';
//meta tag variable to control successful redirect
$metaRef = '';
$ThankFlag = '';

//log entry variable used to build the string to be stored in reglog.txt
$LogEntry = $Yourname."\t".$Companyname."\t".$Email."\t".$Url."\t".Whassup;

//message variable for content that will be sent in text email
$message = "Digital Paw Print web contact\n";
$message .= "Yourname: ".$Yourname."\n";
$message .= "Companyname: ".$Companyname."\n";
$message .= "Email:\t".$Email."\n";
$message .= "Url:\t".$Url."\n";
$message .= "Whassup:\t".$Whassup."\n";

if (!isset($_POST['Email'])) {
//"Rough" check to see if first visit to page. Set welcome message
$FormMessage = 'Please complete all fields that are not marked with "optional".';
}
elseif (empty($Yourname) || empty($Companyname) || empty($Email)|| empty($Url) || empty($Whassup)) {
//check to see if all manditory fields have content. If fails, send error message
$FormMessage = 'Sorry, you must complete all the manditory fields.
Please see fields that are NOT marked as "optional"..';
}
elseif(!is_Email($Email)) {
//check to see if email address is valid. If fails, send error message
$FormMessage = 'Please enter a valid e-mail address';
}
else {
//Write out successful entry to log file
//WriteTXTFile("contactlog.txt", $LogEntry);
//Send email to client
//[email protected]
mail("[email protected]", $message, "From: $Email" );
//set redirect to thank you page with appropriate "info" parameter value. Added to HTML section
//$metaRef = '"';

//NOTE: Commented out header() function as failed with output error
//header( "location: ./contact/ThankYou.php" );
$FormMessage = 'Thank you, your contact request has been sent.';
$ThankFlag = 'true';
}
?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Contact Us

Why not? You've got nothing to lose. Estimates are free. And besides, we're not one of those annoying companies that will bug you incessantly once we have your e-mail address. We also don't give your info out to anyone else.

Wanna talk? Ask us a question? Go for it. We'll tell you what you want to know, then move on as you see fit.

./enquire.php">

Enquiry Form Your Name: " /> Business Name: " /> Your Email Address: " /> Comments: <?php echo $comments;?>

the mail1.inc.php file (in contact folder):

Enquiry Form

html,body,p,div,img,h1,h2,h3,h4,li,ul,ol,dl,dd,dt,form,table,td,tr{
margin:0px;
padding:0px;
border:0px;
border-collapse:separate;
border-spacing:0px;
}
input,select{
margin:0;
padding:0;
}
body{
font-family:verdana,arial,sans-serif;
font-size:100.1%;
}
strong,b{
font-weight:bold;
}
p{
font-size:90%;
line-height:1.1em;
}
#enquireform{
width:401px;
border:1px solid #355981;
padding-bottom:5px;
margin:2em;
}
#enquireform h2{
background:#84ACD8;
border-bottom:1px solid #355981;
margin-bottom:5px;
text-align:center;
font-size:80%;
}
label{
display:inline-block;
}
label{
min-height:1.6em;
font-size:70%;
font-weight:normal;
padding:2px;
border:1px solid #355981;
background:#CDDBE9;
display:block;
width:385px;
margin-bottom:5px;
margin-left:5px;
}
* html label {height:1.6em}
.gr{margin:10px 5px 5px;text-align:center}
.rc{
clear:both;
display:block;
height:1%;
overflow:auto;
border-bottom:5px solid transparent; /* fix for moz browsers collapsing margins */
}
* html .rc{margin-bottom:5px;border:0} /* undoes above fix so IE is OK */
#enquireform label span{
float:left;
display:block;
margin-top:2px;
margin-bottom:2px;
width:125px;
text-align:left;
}
.tf145{
margin:0px 0px 1px 0px;
float:right;
display:inline;
font-size:103%;
width:245px;
height:1.2em;
}
#comments{
margin:0px 0px 1px 0px;
clear:left;
font-size:103%;
width:373px;
font-family:verdana,arial,sans-serif;
}
#submitme{
display:block;
margin:0 auto;
}

and the mail2.inc.php file, also in the "contact" folder:
<?
if ($confirmmessage=="1")
{
?>


Thankyou. Your enquiry was sent to digitalpawprint.com and a confirmation e-mail has been sent to the e-mail address you gave.



<?
}
?>

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

On the first question

On the first question re;
<?phpif (isset($_POST['submitme'])) $submit=addslashes(htmlspecialchars(strip_tags(trim($_POST['submit'])))); ?>

You dont especially need to do anything with this line,all it's doing is checking the value 'submitme' submitted by the form, cleaning it of any nasties, and placing it into a variable called $submit

It reads: if isset(a variable has been set) which is the $_POST[''] containing 'submitme' (this will only be set if the form has been submitted oyherwise $_POST[] will look but not find a value called 'submitme') then take a variable called $submit and into it place the value that is found in $_POST['submit'] however as that is being done pass $_POST['submit'] through a series of php pre-madefunctions these are to perform tasks such as stripping any tags out, adding slashes, removing any whitespace from the data. It's perhaps difficult to read as it nests these functions i.e initially (trim($_POST['submit']) the value 'submit' is trimed of any unwanted space at the ends and returned then it is run through strip_tags removing unwanted code tags and returned untill eventually it's placed into the new variable $submit.

n.b not sure if 'submitme' and 'submit' values should be different without looking deeper.

The only thing you might have to do is to change your form value names at some point to match those above.

More Importantly I'm now worried as you appear to be trying to mix two different scripts? which if the case is going to cause all sorts of problems and confusion , it's one or the other otherwise nothing will work.

Essentially all you're concerned with is the form aspect and it's styling to fit with your site and a success page, Trevas script should allow for dropping in and then just having to adjust a few basic values and styling the form output according to your tastes.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Re that much quote code line

Re that much quote code line with $_POST['submitme'], it needs to be $_POST['submitme'] at both ends, currently you have 'submitme' and 'submit'.

Personally, I think that form handler is horrid. If you find yourself frustrated with it and wish to start again with an alternative post or pm me.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Latest Update

Well I had a small amount of success with this... I got it working for the most part (still some problems, but the basics were operating) although only the sender's name and IP address were e-mailed to me. I then figured out why the company name, e-mail address, and comments were not being sent to me... because the names were still different between enquire.php and enquiryform.inc.php. So I made the necessary adjustments, only to THEN find that the form no longer worked. I've poured over it again and again, to no avail. *sigh*

Can you spot the error?

enquire.php:
<?php
// put your web address instead of the blahblah's in this document!

$enquire_dir="http://www.digitalpawprint.com";

// Read the post variables, strip out hacking code, set internal form variables
if (isset($_POST['submitme'])) $submit=addslashes(htmlspecialchars(strip_tags(trim($_POST['submitme']))));
if (isset($_POST['Yourname'])) $namefrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['Yourname']))));
if (isset($_POST['Companyname'])) $businessfrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['Companyname']))));
if (isset($_POST['Email'])) $emailfrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['Email']))));
if (isset($_POST['Url'])) $urlfrom=addslashes(htmlspecialchars(strip_tags(trim($_POST['Url']))));
if (isset($_POST['Whassup'])) $comments=addslashes(htmlspecialchars(strip_tags(trim($_POST['Whassup']))));

if (!isset($_POST['submitme'])):
//This html is the actual form
include ("./enquire/mail1.inc.php");
include ("./enquire/enquireform.inc.php");
include ("./enquire/mail2.inc.php");
//end of actual form html

else:

/* error function */

function error($msg) {
global $Yourname,$Companyname,$Email,$Url,$Whassup,$enquire_dir;
include ("./enquire/mail1.inc.php");
echo $msg;
include ("./enquire/enquireform.inc.php");
include ("./enquire/mail2.inc.php");
exit;
}

/* Check for blanks start */
// these 4 lines check for blanks and display an error if they are found. You will need to add or remove items
// from this block to add or remove required fields, please follow the format already laid out.

if ($Yourname=="" or $Companyname=="" or $Email=="" or $Url=="" or $Whassup=="") {
error("

Not Sent: One or more required fields were left blank.

The fields marked in red must be completed.

Please fill them in and re-submit.

");
}
/* check for blank end */

//email blocker start - to block from emails. add more as shown with x's
if ($Email=="[email protected]" or $Email=="[email protected]"){
error("

Not Sent: You are not authorised.

xxxxxxxxxxx

");
}
//end

//ip address blocker start - simply add more as sshown with x's to expand
if ($_SERVER["REMOTE_ADDR"]=="10.10.10.10"){
error("

Not Sent: You are not authorised.

xxxxxxxxxxx

");
}
//end

/* email validation start - checks correct eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6e%61%6d%65%40%68%6f%73%74%2e%65%78%74%22%3e%6e%61%6d%65%40%68%6f%73%74%2e%65%78%74%3c%2f%61%3e%27%29%3b')) form*/
// if you do not wish to use email validation or email is not a required field (above),
// comment out the following 4 code lines by adding a // at the beginning as has been
// done here.

if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[[email protected]]+$", $Email))) {
error("

Not Sent: Invalid email address.

Please correct this and try again.

");
}

/* email validation end */

//finally, send our email and show confirmation. I have commented this out, you need to remove the slash star
//and star slash, fill in the details and text on a real server!

$body="The following enquiry was made via the digitalpawprint.com website:\n\nThe contact's details are as
follows:\n\n$Yourname\n$message\nIP Logged: $REMOTE_ADDR\n\n";
mail("[email protected]", "digitalpawprint.com Website Enquiry", $body,
"From: $Yourname <$emailfrom\n");
mail($Email, "Digital Paw Print", "Thankyou for your message!\n\nWe will contact you
as soon as we're able to do so.\n\nPlease note that this is an automated response
to your enquiry at www.digitalpawprint.com.\n\n\n\n\n\nDigital Paw Print\", "From: DPP

enquireform.inc.php:

<?php

/* TODO: Add code here */
/*
========================================================================
-- function WriteTXTFile($filenm, $InputStr) --
Function to write out information to an existing text file. Function
opens existing file, reads in it's content and then concatenates new
string to existing content and re-writes to file.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
$InputStr - string to be concatenated to existing file content and
written to the file.
------------------------------------------------------------------------
Output:
- None -
========================================================================
*/
function WriteTXTFile($filenm, $InputStr){
$content = ReadTXTFile($filenm);
$content .= $InputStr;
$fileh = fopen($filenm, 'w') or die("Can't open file");
fwrite($fileh, $content);
fclose($fileh);
}

/*
========================================================================
-- function ReadTXTFile($filename) --
Function to read information from an existing text file. Function opens
an existing file, reads the entire content and returns the content.
------------------------------------------------------------------------
Input:
$filenm - string file name of text file that exists in the same folder
as this calling script
------------------------------------------------------------------------
Output:
return - string content of all existing content within the file
========================================================================
*/
function ReadTXTFile($filename) {
$fh = fopen($filename, 'r');
$theData = fread($fh, filesize($filename));
fclose($fh);
return $theData;
}

/*
========================================================================
-- function is_Email($Addr) --
Function to validate correct email format. Uses regualr expression
matching
------------------------------------------------------------------------
Input:
$Addr - string email address
------------------------------------------------------------------------
Output:
return - boolean
========================================================================
*/
function is_Email($Addr)
{
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum)$/ix';
return preg_match($p, $Addr);
}

//Variables - Names are self explainitory, set each one with post variables. Will be empty on first load
$Yourname = $_POST['Yourname'] ;
$Companyname = $_POST['Companyname'] ;
$Email = $_POST['Email'] ;
$Url = $_POST['Url'] ;
$Whassup = $_POST['Whassup'] ;
//message variable to return error message
$FormMessage = '';
//meta tag variable to control successful redirect
$metaRef = '';
$ThankFlag = '';

//log entry variable used to build the string to be stored in reglog.txt
$LogEntry = $Yourname."\t".$Companyname."\t".$Email."\t".$Url."\t".Whassup;

//message variable for content that will be sent in text email
$message = "Digital Paw Print web contact\n";
$message .= "Yourname: ".$Yourname."\n";
$message .= "Companyname: ".$Companyname."\n";
$message .= "Email:\t".$Email."\n";
$message .= "Url:\t".$Url."\n";
$message .= "Whassup:\t".$Whassup."\n";

if (!isset($_POST['Email'])) {
//"Rough" check to see if first visit to page. Set welcome message
$FormMessage = 'Please complete all fields that are not marked with "optional".';
}
elseif (empty($Yourname) || empty($Companyname) || empty($Email)|| empty($Url) || empty($Whassup)) {
//check to see if all manditory fields have content. If fails, send error message
$FormMessage = 'Sorry, you must complete all the manditory fields.
Please see fields that are NOT marked as "optional"..';
}
elseif(!is_Email($Email)) {
//check to see if email address is valid. If fails, send error message
$FormMessage = 'Please enter a valid e-mail address';
}
else {
//Write out successful entry to log file
//WriteTXTFile("contactlog.txt", $LogEntry);
//Send email to client
//[email protected]
mail("[email protected]", $message, "From: $Email" );
//set redirect to thank you page with appropriate "info" parameter value. Added to HTML section
//$metaRef = '"';

//NOTE: Commented out header() function as failed with output error
//header( "location: ./contact/ThankYou.php" );
$FormMessage = 'Thank you, your contact request has been sent.';
$ThankFlag = 'true';
}
?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Contact Us

Why not? You've got nothing to lose. Estimates are free. And besides, we're not one of those annoying companies that will bug you incessantly once we have your e-mail address. We also don't give your info out to anyone else.

Wanna talk? Ask us a question? Go for it. We'll tell you what you want to know, then move on as you see fit.

../enquire.php"> Your Name: " /> Company Name: " /> Your E-mail Address: " /> Website Address: " /> Whassup: <?php echo $Whassup;?>

mail1.inc.php:

Enquiry Form

html,body,p,div,img,h1,h2,h3,h4,li,ul,ol,dl,dd,dt,form,table,td,tr{
margin:0px;
padding:0px;
border:0px;
border-collapse:separate;
border-spacing:0px;
}
input,select{
margin:0;
padding:0;
}
body{
font-family:verdana,arial,sans-serif;
font-size:100.1%;
}
strong,b{
font-weight:bold;
}
p{
font-size:90%;
line-height:1.1em;
}
#enquireform{
width:401px;
border:1px solid #355981;
padding-bottom:5px;
margin:2em;
}
#enquireform h2{
background:#84ACD8;
border-bottom:1px solid #355981;
margin-bottom:5px;
text-align:center;
font-size:80%;
}
label{
display:inline-block;
}
label{
min-height:1.6em;
font-size:70%;
font-weight:normal;
padding:2px;
border:1px solid #355981;
background:#CDDBE9;
display:block;
width:385px;
margin-bottom:5px;
margin-left:5px;
}
* html label {height:1.6em}
.gr{margin:10px 5px 5px;text-align:center}
.rc{
clear:both;
display:block;
height:1%;
overflow:auto;
border-bottom:5px solid transparent; /* fix for moz browsers collapsing margins */
}
* html .rc{margin-bottom:5px;border:0} /* undoes above fix so IE is OK */
#enquireform label span{
float:left;
display:block;
margin-top:2px;
margin-bottom:2px;
width:125px;
text-align:left;
}
.tf145{
margin:0px 0px 1px 0px;
float:right;
display:inline;
font-size:103%;
width:245px;
height:1.2em;
}
#comments{
margin:0px 0px 1px 0px;
clear:left;
font-size:103%;
width:373px;
font-family:verdana,arial,sans-serif;
}
#submitme{
display:block;
margin:0 auto;
}

mail2.inc.php:







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Message Sent

<? if ($confirmmessage=="1") { ?>

Thankyou for contacting us! Your enquiry was sent to digitalpawprint.com and a confirmation e-mail has been sent to the e-mail address you gave. We'll be in touch as soon as possible.

<? } ?>

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Lamb sorry for slow

Lamb sorry for slow response.

I would have thought your form action was a problem

action="<?php echo $enquire_dir;?>../enquire.php">

Where $enquire_dir = http://www.digitalpawprint.com

should give you
http://www.digitalpawprint.com../enquire.php

Mixing an absolute ref url with a relative one

In your enquireform.php can you isolate or remove that portion of script that is the original version as that just confuses matters and is being run even if not doing much.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Interesting ~ I removed that

Interesting ~ I removed that portion of code that you mentioned, and now when I hit the "Send it" button, it reloads the same page with the information still filled in. A step forward, definitely, as at least I don't get a "can't load page" message.

What might be next?

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Lamb I don't know what

Lamb I don't know what 'portion' of code you have commented out but I don't think it was the one I was referring to. The only script that seems capable of retuning those form values populated is the the one contained in the file that has your form html markup and which is being 'included' via Trevas script (the first file).

You simply have to sort out which script you're using and discard the other as this is confusing the issue greatly, you have one script calling a different one and the two clashing.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I keep changing my post as I think this over...

I'm going to look over Treva's example again, as I'm a bit confused (obviously) at the moment... I thought I was using only and all that he said must be used... a form called enquiry.php, one called enquireform.inc.php, one called mail1.inc.php, and one called mail2.inc.php.

I've commented out any references to $enquiry_dir in the first two pages, in hopes of that helping... so far no good, but I'll keep at it. As always, I must be missing something relatively obvious.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Following Hugo's advice

I see what you mean, Hugo ~ I've got some of Treva's stuff mixed with some of the original code I got from a developer I worked with, and obviously the two don't mix and, as you pointed out, are clashing with one another.

I think what I'm going to have to do is to redo it with ONLY Treva's code, and it will most likely be far easier for me to work with and for you to look at if necessary.

Thanks for your patience... I'll post again with the results once I've completed that.

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

If you want to look at an

If you want to look at an alternative, take a look here. Notice the surrounding page is next to irrelevant, the form and its handler are simply included when they need to be used.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Looking at Chris' new stuff

Thanks for the link, Chris ~ I've got a number of questions before I tackle anything though.

1) How come there's three working pages and seven pages of source code? Is all of that needed to make it work, or was it showing different examples of different ways to go about it or something like that? I must confess after the first page or two of source code, I couldn't make head nor tail of it. This is clearly due to the fact that I'm new to PHP though.

2) "Notice the surrounding page is next to irrelevant" ~ by this, do you mean the surrounding page as in the ipsum latin stuff on the main part of the page, in comparison to the actual contact details on the side?

3) "the form and its handler are simply included when they need to be used" ~ by form, do you mean the contact details that are being filled in?

4) I feel like such an idiot asking this... but what's a handler?

5) Is that your site? The design is fantastic.

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

There are only two working

There are only two working pages. There are two links to the contact page, one with redirect=yes and one with redirect=no. Under "production" circumstances redirecting would be preset either way so there would be no need for the query string. I added it to show the page working both ways.

PHP is complex. If you do things properly you end up with a grab bag of functions that do useful stuff. Once they are written, there is no point separating them out, just include the file and get access to the functionality. The last three files are those. Read through them.
- common.php is a mixed bag of input filtering, output functions, mail wrappers, etc
- mysql.class.php is a mysql wrapper for when the form data goes into a db
- functions.php is a very few functions specific to form handling, e.g file uploading and field highlighting (submit the form empty or supply an illegal email address, it looks best when google doesn't interfere with the field background).

the other four files are specific to a contact form
- contact.php the page which holds the contact form, pretty well only html and a couple of includes. This is essentially a copy of the site template with a couple of bits of php.
- include/contact.php the form handler* it does all the processing and doesn't care about the html
- include/form.tpl.php the form itself, primarily html with some php to echo variable values
- thank_you.html only required if you redirect on success. A simple page, no php.

One of the objectives in coding is to keep different parts separate. This helps with reuse later. E.g. when you do your next contact form you don't want to start from scratch again. With the above code, I can take a page from the website, copy it, remove the content and replace with an include for form.tpl.php tack one line of php at the top of the page to include the form handler and maybe create a second basic page with the content replaced by a thank you message. The form handler is done with a few variable alterations (at the top), the form itself needs nothing except maybe some change in labels. All that needs doing is to add some styles for the form to fit in with the site design.

2) Yes. Take a look at the page source ... there is the page and there is an include for the form. As I mention above. You build a site, it probably has a content div and a sidebar div. When you come to the contact form. Remove the content from one of those and include the form there. Voila!

3) No. Compare the thank_you page with the contact form page. Remove the text content from both and they are virtually identical except for a couple of lines of php.

4) See * below.

5) No. Its a page from site for which I did several inquiry pages two weeks ago - anonymised.

*a handler, handles the processing for something. A form handler will handle the processing required by a form.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

This is great ~ thank you!

This is great ~ thank you! It looks like I've got my work cut out for me... I'm going to scrap what I've done so far, since it's pretty much a jumbled mess, and start fresh with your sample.

At this point, would it be best for me to just PM you (Chris S.) with questions in relation to this, or should I keep this thread going?

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Keep the thread going. I'll

Keep the thread going. I'll answer if and when I can. As I expect will others.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I've been kept away from

I've been kept away from working on this for a few days, so have only today gotten back to it. I copied out the code, created files and folders, uploaded, and tried it out. The contact form (the only one I've attempted thus far) worked!

Aside from altering the code so that it fits in stylistically with my site, there's just one thing I'd like to first adjust...

After submitting, the thank_you message successfully appears. The only thing I'm not fond of is the fact that the thankyou message appears with another fresh contact form sitting beneath it... I would prefer that the thank you message appears by itself. In the rare case that the user wants to fill out the form again and send more or different info, I'd rather that they click on the contact section to get back to the form and start the process fresh.

I had a look at the thank_you code, and it's definitely separate from the form. So why would the form be appearing beneath?

Once I clear this up, I'll move on to getting things connected with my CSS page. Might need some help with it, we'll see. I'm looking forward to giving it a shot myself to begin with, so I'll keep you posted... but first things first.

http://www.digitalpawprint.com/contact/contact.php

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Without seeing your code its

Without seeing your code its difficult to know what you mean.

My version is set up with two alternatives for the thank you message. The best method is to use the redirect to a separate page, e.g. define('_REDIRECT_', true); and setup the redirect url (I give reasons why redirecting is the best method above).

The other alternative (_REDIRECT_ == false) shown in my code is to replace the page content with a thank you message. The form code is not affected by this. To hide the form code you should wrap it in a PHP conditional in a similar manner to that around the page content.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I should mention in advance

I should mention in advance that I've discovered a few health issues on my Mac (where I do all of this work) and might disappear for a day or so again when I take it to my ever-so-fabulous-techie-brother, who quickly and efficiently fixes my machines for the mere cost of home-baked goods. (an excellent arrangement, as we both believe we each have the longer end of the stick).

I played about with things a bit, and managed to take a step backwards much to my chagrin. Now instead of seeing the Thank You message with a new empty form beneath (after submitting info), I submit the info and I only see a new form with no Thank You message. Ah pooh.

So here's my code... I think you only need me to list contact.php, include/contact.php, and thank_you.html as these are the only ones I've played with. If you require more, I'll be happy to list more code. So here goes:

contact.php:
<?php define('_JALAKAI_',true); include('include/contact.php'); ?>

Jalakai Designs :: Contact Form

Digital Paw Print

This is the contact form page. <?php if (empty($notification_success)) { ?>

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec pede dolor, pellentesque non, congue id, malesuada et, tellus. Cras orci nisl, porttitor sed, commodo non, scelerisque quis, dui. Quisque non ipsum ac leo rutrum placerat. In fringilla condimentum urna.

Fusce malesuada, turpis vel cursus hendrerit, tortor lectus dictum felis, eu lacinia ipsum odio sed felis. Vivamus est orci, convallis sit amet, mattis at, convallis at, tellus. Nunc gravida leo eu diam. Nunc mauris leo, faucibus vitae, blandit in, sodales quis, nibh. Fusce eget felis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;

  • Lorem ipsum dolor
  • Fusce malesuada
  • Donec congue arcu vel metus
  • Etiam condimentum eros id odio
  • Fusce posuere

>> learn more

<?php } else { ?>

Thank you for your interest in ...!
Please fully complete and submit the form below for us to contact you.

<?php } ?>

include/contact.php:
<?php
/*
* contact us form processor script
*
* @author christopher smith
* @date 2007-06-25
*
* (c)2007 Jalakai Designs
*/
if (!defined(_JALAKAI_) && !_JALAKAI_) die();

define('DEBUG',false);
define('_DB_',false);
define('_REDIRECT_',(!empty($_REQUEST['redirect']) && ($_REQUEST['redirect']=='true'))); // for success - set to true to redirect, false to return to the same page

// email addresses to receive notification of an inquiry
$notify_addresses = array('[email protected]');
$notify_subject = '%s - Customer Inquiry';

// admin/support email address
$email_admin = '[email protected]';

// email addresses from the following services will trigger an error,
// the list will be used in a preg function, escape any special characters
// use an empty array, "$banned_domains = array();" to exclude noone.
$banned_domains = array('gmail','googlemail','hotmail','yahoo','aol');


// DB configuration
if (_DB_) {
define('_DB_CONNECTION_','db');
define('_DB_TABLE_','contact');
}
if (_REDIRECT_) {

$host = $_SERVER['HTTP_HOST'];
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$page = 'thank_you.html'; // set to redirect page name

$redirect_uri = "http://$host$path/$page";
}

require_once (dirname(__FILE__).'/common.php');
require_once (dirname(__FILE__).'/functions.php');

$error = false;
$msg = array();
global $highlight; $highlight = array();
$internal_error_msg = 'There was an internal error while processing your request. Please try again later. If the problem persists, please contact customer service at '.$email_admin.'.';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$raw_firstname = cleanInputString('first_name');
$raw_lastname = cleanInputString('last_name');
$raw_company = cleanInputString('company');
$raw_phone = cleanInputString('phone');
$raw_email = cleanInputString('email');
$raw_website = cleanInputString('website');
$raw_more = cleanInputString('more_info');

// create variables to hold data for insertion into the db and notification message text
$insert = array();
$message = '';

if (empty($raw_firstname) && empty($raw_lastname)) {

$error = true;
$msg[] = 'Please provide a your name.';
$highlight[] = 'first_name';
$highlight[] = 'last_name';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_firstname.$raw_lastname)) {

$error = true;
$msg[] = 'Illegal characters detected in name.';
if (preg_match('/[[:cntrl:]<>]/',$raw_firstname)) $highlight[] = 'first_name';
if (preg_match('/[[:cntrl:]<>]/',$raw_lastname)) $highlight[] = 'last_name';

} else {

$insert['first_name'] = $raw_firstname;
$insert['last_name'] = $raw_lastname;
$message .= "Name: {$raw_firstname} {$raw_lastname}\n";

}

// company must exist
if (empty($raw_company)) {

$error = true;
$msg[] = 'Please include your company.';
$highlight[] = 'company';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_company)) {

$error = true;
$msg[] = 'Illegal characters detected in company.';
$highlight[] = 'company';

} else {

$insert['company'] = $raw_company;
$message .= 'Company: '.$raw_company."\n";

}

// phone must exist
if (empty($raw_phone)) {

$error = true;
$msg[] = 'The phone number is missing.';
$highlight[] = 'phone';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_phone)) {

$error = true;
$msg[] = 'Illegal characters detected in phone number.';
$highlight[] = 'phone';

} else {

$insert['phone'] = $raw_phone;
$message .= 'Phone: '.$raw_phone."\n";

}

// email must exist, be valid & not be from banned domain list
if (empty($raw_email) || !isValidEmail($raw_email)) {

$error = true;
$msg[] = 'The email address is missing or invalid.';
$highlight[] = 'email';

} else if (isBannedDomain($raw_email, $banned_domains)) {

$error = true;
$msg[] = 'The email address is from a public email service, please use a company email address.';
$highlight[] = 'email';

} else {

$insert['email'] = $raw_email;
$message .= 'Email: '.$raw_email."\n";

}

if (empty($raw_website)) {

$error = true;
$msg[] = 'Please provide your website address.';
$highlight[] = 'website';

} else if (preg_match('/[[:cntrl:]]/',$raw_subject)) {

$error = true;
$msg[] = 'Illegal characters detected in website.';
$highlight[] = 'website';

} else {

$insert['website'] = $raw_website;
$message .= 'Website: '.$raw_website."\n";

}

if (empty($raw_more)) {

$error = true;
$msg[] = 'Please tell us the nature of your inquiry.';
$highlight[] = 'more_info';

} else if (preg_match('/[\x01-\x08\x0b\x0c\x0e-\x1f]/',$raw_more)) {

$error = true;
$msg[] = 'Illegal characters detected in Inquiry Detail.';
$highlight[] = 'more_info';

} else {

$insert['more_info'] = $raw_more;
$message .= "\nInquiry Detail\n==========================\n".$raw_more."\n";

}

if (!$error) {

if (_DB_) {
require_once (dirname(__FILE__).'/mysql.class.php');
$db = new db();
$db->connect(_DB_CONNECTION_);

$ok = $db->insert(_DB_TABLE_,array($insert));
} else {

$ok = true;

}

// send notification email
if (!empty($notify_addresses)) {
// determine topic from calling page
$topic = ucwords(strtr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4),'-_',' '));
$message = $topic."\n====================\n\n".$message;
$notify_subject = sprintf($notify_subject, $topic);

$from = "{$insert['name']} <{$insert['email']}>";
$mail_ok = notify($notify_addresses,$notify_subject,$from,$message);
}


if ($ok) {

if (_REDIRECT_) {
header("location: {$redirect_uri}");
exit();
} else {
$notification_success = true;

$raw_firstname = '';
$raw_lastname = '';
$raw_company = '';
$raw_phone = '';
$raw_email = '';
$raw_website = '';
$raw_more = '';

}

} else {

$error = true;
$msg[] = $internal_error_msg;

}
}
} else {

$raw_firstname = '';
$raw_lastname = '';
$raw_company = '';
$raw_phone = '';
$raw_email = '';
$raw_website = '';
$raw_more = '';

}

thank_you.html:

Jalakai Designs :: Thank you

Digital Paw Print

This is the Thank You page.

Thank you for your interest in printers' latin!
A sales representative will contact you shortly.

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

the _REDIRECT_ line at the

the _REDIRECT_ line at the top of include/contact.php should be

define('_REDIRECT_',true);

Also, I think you have another copy of the page where you haven't changed the notify address. Do you mind changing it Wink

You can also remove the Copyright Jalakai Designs from the HTML pages and <TITLE>.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I'm getting a parsing error

I'm getting a parsing error on line 14, which is this line:

define('_REDIRECT_',true) && ($_REQUEST['redirect']=='true')));

What is it that is incorrect? I suspect I might have removed something I shouldn't have.

Sorry about the notify address oversight! You must have been getting bombarded with "tests" from me. :rolleyes: I'm pretty sure I've got them all covered now, but please let me know if you receive any more in case I missed something essential somehow.

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 1 year 23 weeks ago
Bournemouth
Joined: 2007-05-31
Posts: 693
Points: 45

Brackets

Is it just me or do the brackets not add up?

Cheers,

Johnny B

Have YOU said Hello yet?
The CSSCreator Hello Thread

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

I tried this

I tried this:

define('_REDIRECT_',true) && ($_REQUEST['redirect']=='true');

but with that, I just found that the page could not be displayed. I'm sure I must have cut out some essential part of the code.

So then I tried this:

define('_REDIRECT_'true,(!empty($_REQUEST['redirect']) && ($_REQUEST['redirect']=='true')));

but same thing... the page could not be displayed.

Here's the whole page (include/contact.php):

<?php /* * contact us form processor script * * @author jenn fantham * @date 2007-06-25 * * (c)2007 Digital Paw Print */ if (!defined(_DPP_) && !_DPP_) die(); define('DEBUG',false); define('_DB_',false); define('_REDIRECT_'true,(!empty($_REQUEST['redirect']) && ($_REQUEST['redirect']=='true'))); // for success - set to true to redirect, false to return to the same page // email addresses to receive notification of an inquiry $notify_addresses = array('[email protected]'); $notify_subject = '%s - Customer Inquiry'; // admin/support email address $email_admin = '[email protected]'; // email addresses from the following services will trigger an error, // the list will be used in a preg function, escape any special characters // use an empty array, "$banned_domains = array();" to exclude noone. $banned_domains = array('gmail','googlemail','hotmail','yahoo','aol'); // DB configuration if (_DB_) { define('_DB_CONNECTION_','db'); define('_DB_TABLE_','contact'); } if (_REDIRECT_) { $host = $_SERVER['HTTP_HOST']; $path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $page = 'thank_you.html'; // set to redirect page name $redirect_uri = "http://$host$path/$page"; } require_once (dirname(__FILE__).'/common.php'); require_once (dirname(__FILE__).'/functions.php'); $error = false; $msg = array(); global $highlight; $highlight = array(); $internal_error_msg = 'There was an internal error while processing your request. Please try again later. If the problem persists, please contact customer service at '.$email_admin.'.'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $raw_firstname = cleanInputString('first_name'); $raw_lastname = cleanInputString('last_name'); $raw_company = cleanInputString('company'); $raw_phone = cleanInputString('phone'); $raw_email = cleanInputString('email'); $raw_website = cleanInputString('website'); $raw_more = cleanInputString('more_info'); // create variables to hold data for insertion into the db and notification message text $insert = array(); $message = ''; if (empty($raw_firstname) && empty($raw_lastname)) { $error = true; $msg[] = 'Please provide a your name.'; $highlight[] = 'first_name'; $highlight[] = 'last_name'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_firstname.$raw_lastname)) { $error = true; $msg[] = 'Illegal characters detected in name.'; if (preg_match('/[[:cntrl:]<>]/',$raw_firstname)) $highlight[] = 'first_name'; if (preg_match('/[[:cntrl:]<>]/',$raw_lastname)) $highlight[] = 'last_name'; } else { $insert['first_name'] = $raw_firstname; $insert['last_name'] = $raw_lastname; $message .= "Name: {$raw_firstname} {$raw_lastname}\n"; } // company must exist if (empty($raw_company)) { $error = true; $msg[] = 'Please include your company.'; $highlight[] = 'company'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_company)) { $error = true; $msg[] = 'Illegal characters detected in company.'; $highlight[] = 'company'; } else { $insert['company'] = $raw_company; $message .= 'Company: '.$raw_company."\n"; } // phone must exist if (empty($raw_phone)) { $error = true; $msg[] = 'The phone number is missing.'; $highlight[] = 'phone'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_phone)) { $error = true; $msg[] = 'Illegal characters detected in phone number.'; $highlight[] = 'phone'; } else { $insert['phone'] = $raw_phone; $message .= 'Phone: '.$raw_phone."\n"; } // email must exist, be valid & not be from banned domain list if (empty($raw_email) || !isValidEmail($raw_email)) { $error = true; $msg[] = 'The email address is missing or invalid.'; $highlight[] = 'email'; } else if (isBannedDomain($raw_email, $banned_domains)) { $error = true; $msg[] = 'The email address is from a public email service, please use a company email address.'; $highlight[] = 'email'; } else { $insert['email'] = $raw_email; $message .= 'Email: '.$raw_email."\n"; } if (empty($raw_website)) { $error = true; $msg[] = 'Please provide your website address.'; $highlight[] = 'website'; } else if (preg_match('/[[:cntrl:]]/',$raw_subject)) { $error = true; $msg[] = 'Illegal characters detected in website.'; $highlight[] = 'website'; } else { $insert['website'] = $raw_website; $message .= 'Website: '.$raw_website."\n"; } if (empty($raw_more)) { $error = true; $msg[] = 'Please tell us the nature of your inquiry.'; $highlight[] = 'more_info'; } else if (preg_match('/[\x01-\x08\x0b\x0c\x0e-\x1f]/',$raw_more)) { $error = true; $msg[] = 'Illegal characters detected in Inquiry Detail.'; $highlight[] = 'more_info'; } else { $insert['more_info'] = $raw_more; $message .= "\nInquiry Detail\n==========================\n".$raw_more."\n"; } if (!$error) { if (_DB_) { require_once (dirname(__FILE__).'/mysql.class.php'); $db = new db(); $db->connect(_DB_CONNECTION_); $ok = $db->insert(_DB_TABLE_,array($insert)); } else { $ok = true; } // send notification email if (!empty($notify_addresses)) { // determine topic from calling page $topic = ucwords(strtr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4),'-_',' ')); $message = $topic."\n====================\n\n".$message; $notify_subject = sprintf($notify_subject, $topic); $from = "{$insert['name']} <{$insert['email']}>"; $mail_ok = notify($notify_addresses,$notify_subject,$from,$message); } if ($ok) { if (_REDIRECT_) { header("location: {$redirect_uri}"); exit(); } else { $notification_success = true; $raw_firstname = ''; $raw_lastname = ''; $raw_company = ''; $raw_phone = ''; $raw_email = ''; $raw_website = ''; $raw_more = ''; } } else { $error = true; $msg[] = $internal_error_msg; } } } else { $raw_firstname = ''; $raw_lastname = ''; $raw_company = ''; $raw_phone = ''; $raw_email = ''; $raw_website = ''; $raw_more = ''; }

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 1 year 23 weeks ago
Bournemouth
Joined: 2007-05-31
Posts: 693
Points: 45

It can't handle the truth!

Aren't you missing a comma here??

... define('_REDIRECT_'true,(! ...

In between the '_REDIRECT_' and the true??

John

P.S. I'm on form with my Subject titles today Laughing out loud

Have YOU said Hello yet?
The CSSCreator Hello Thread

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Kack.

The comma was in the wrong place, but that didn't solve it.

But then I had a slight revelation when I realized what a complete eeediot I am, as I somehow missed the simple explanation that Chris S. offered... that the line should be just what he said, a few comments above. I was trying to adjust the line to what he suggested, while still keeping the rest of the crap after it.

So I put only and exactly what he suggested on that line... but still the page will not display for some reason. Gah!

Here's the code now, with the line #14 being the one I've been playing with...

<?php
/*
* contact us form processor script
*
* @author jenn fantham
* @date 2007-06-25
*
* (c)2007 Digital Paw Print
*/
if (!defined(_DPP_) && !_DPP_) die();

define('DEBUG',false);
define('_DB_',false);
define('_REDIRECT_',true); // for success - set to true to redirect, false to return to the same page

// email addresses to receive notification of an inquiry
$notify_addresses = array('[email protected]');
$notify_subject = '%s - Customer Inquiry';

// admin/support email address
$email_admin = '[email protected]';

// email addresses from the following services will trigger an error,
// the list will be used in a preg function, escape any special characters
// use an empty array, "$banned_domains = array();" to exclude noone.
$banned_domains = array('gmail','googlemail','hotmail','yahoo','aol');


// DB configuration
if (_DB_) {
define('_DB_CONNECTION_','db');
define('_DB_TABLE_','contact');
}
if (_REDIRECT_) {

$host = $_SERVER['HTTP_HOST'];
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$page = 'thank_you.html'; // set to redirect page name

$redirect_uri = "http://$host$path/$page";
}

require_once (dirname(__FILE__).'/common.php');
require_once (dirname(__FILE__).'/functions.php');

$error = false;
$msg = array();
global $highlight; $highlight = array();
$internal_error_msg = 'There was an internal error while processing your request. Please try again later. If the problem persists, please contact customer service at '.$email_admin.'.';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$raw_firstname = cleanInputString('first_name');
$raw_lastname = cleanInputString('last_name');
$raw_company = cleanInputString('company');
$raw_phone = cleanInputString('phone');
$raw_email = cleanInputString('email');
$raw_website = cleanInputString('website');
$raw_more = cleanInputString('more_info');

// create variables to hold data for insertion into the db and notification message text
$insert = array();
$message = '';

if (empty($raw_firstname) && empty($raw_lastname)) {

$error = true;
$msg[] = 'Please provide a your name.';
$highlight[] = 'first_name';
$highlight[] = 'last_name';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_firstname.$raw_lastname)) {

$error = true;
$msg[] = 'Illegal characters detected in name.';
if (preg_match('/[[:cntrl:]<>]/',$raw_firstname)) $highlight[] = 'first_name';
if (preg_match('/[[:cntrl:]<>]/',$raw_lastname)) $highlight[] = 'last_name';

} else {

$insert['first_name'] = $raw_firstname;
$insert['last_name'] = $raw_lastname;
$message .= "Name: {$raw_firstname} {$raw_lastname}\n";

}

// company must exist
if (empty($raw_company)) {

$error = true;
$msg[] = 'Please include your company.';
$highlight[] = 'company';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_company)) {

$error = true;
$msg[] = 'Illegal characters detected in company.';
$highlight[] = 'company';

} else {

$insert['company'] = $raw_company;
$message .= 'Company: '.$raw_company."\n";

}

// phone must exist
if (empty($raw_phone)) {

$error = true;
$msg[] = 'The phone number is missing.';
$highlight[] = 'phone';

} else if (preg_match('/[[:cntrl:]<>]/',$raw_phone)) {

$error = true;
$msg[] = 'Illegal characters detected in phone number.';
$highlight[] = 'phone';

} else {

$insert['phone'] = $raw_phone;
$message .= 'Phone: '.$raw_phone."\n";

}

// email must exist, be valid & not be from banned domain list
if (empty($raw_email) || !isValidEmail($raw_email)) {

$error = true;
$msg[] = 'The email address is missing or invalid.';
$highlight[] = 'email';

} else if (isBannedDomain($raw_email, $banned_domains)) {

$error = true;
$msg[] = 'The email address is from a public email service, please use a company email address.';
$highlight[] = 'email';

} else {

$insert['email'] = $raw_email;
$message .= 'Email: '.$raw_email."\n";

}

if (empty($raw_website)) {

$error = true;
$msg[] = 'Please provide your website address.';
$highlight[] = 'website';

} else if (preg_match('/[[:cntrl:]]/',$raw_subject)) {

$error = true;
$msg[] = 'Illegal characters detected in website.';
$highlight[] = 'website';

} else {

$insert['website'] = $raw_website;
$message .= 'Website: '.$raw_website."\n";

}

if (empty($raw_more)) {

$error = true;
$msg[] = 'Please tell us the nature of your inquiry.';
$highlight[] = 'more_info';

} else if (preg_match('/[\x01-\x08\x0b\x0c\x0e-\x1f]/',$raw_more)) {

$error = true;
$msg[] = 'Illegal characters detected in Inquiry Detail.';
$highlight[] = 'more_info';

} else {

$insert['more_info'] = $raw_more;
$message .= "\nInquiry Detail\n==========================\n".$raw_more."\n";

}

if (!$error) {

if (_DB_) {
require_once (dirname(__FILE__).'/mysql.class.php');
$db = new db();
$db->connect(_DB_CONNECTION_);

$ok = $db->insert(_DB_TABLE_,array($insert));
} else {

$ok = true;

}

// send notification email
if (!empty($notify_addresses)) {
// determine topic from calling page
$topic = ucwords(strtr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4),'-_',' '));
$message = $topic."\n====================\n\n".$message;
$notify_subject = sprintf($notify_subject, $topic);

$from = "{$insert['name']} <{$insert['email']}>";
$mail_ok = notify($notify_addresses,$notify_subject,$from,$message);
}


if ($ok) {

if (_REDIRECT_) {
header("location: {$redirect_uri}");
exit();
} else {
$notification_success = true;

$raw_firstname = '';
$raw_lastname = '';
$raw_company = '';
$raw_phone = '';
$raw_email = '';
$raw_website = '';
$raw_more = '';

}

} else {

$error = true;
$msg[] = $internal_error_msg;

}
}
} else {

$raw_firstname = '';
$raw_lastname = '';
$raw_company = '';
$raw_phone = '';
$raw_email = '';
$raw_website = '';
$raw_more = '';

}

Thanks for your ideas, Burlster... the solution is bound to surface at some point!

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Few points:

Few points:

Post your contact.php form as well as the included form processor script,

Are you getting any error messages? have you got some form of error message output at work?

What editor are you using ? is it one that can check for syntax errors? as that is a big help initially, if not download something like tsWebEditor as it will check syntax and show you any errors against line numbers.

When Chris said to remove the copyright I don't think he really meant change it to DPP or the authorship line, it would be polite to leave original source attribution intact, with perhaps a 'modified and adapted by' line or something similar, in other words the script should in some senses be treated as ccovered by a CC licence, although that's Chris's decision

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Here is the other form,

Here is the other form, contact.php:

<?php define('_DPP_',true); include('include/contact.php'); ?>

Digital Paw Print :: Contact Form

Digital Paw Print

This is the contact form page. <?php if (empty($notification_success)) { ?>

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec pede dolor, pellentesque non, congue id, malesuada et, tellus. Cras orci nisl, porttitor sed, commodo non, scelerisque quis, dui. Quisque non ipsum ac leo rutrum placerat. In fringilla condimentum urna.

Fusce malesuada, turpis vel cursus hendrerit, tortor lectus dictum felis, eu lacinia ipsum odio sed felis. Vivamus est orci, convallis sit amet, mattis at, convallis at, tellus. Nunc gravida leo eu diam. Nunc mauris leo, faucibus vitae, blandit in, sodales quis, nibh. Fusce eget felis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;

  • Lorem ipsum dolor
  • Fusce malesuada
  • Donec congue arcu vel metus
  • Etiam condimentum eros id odio
  • Fusce posuere

>> learn more

<?php } else { ?>

Thank you for your interest in ...!
Please fully complete and submit the form below for us to contact you.

<?php } ?>

I'm not getting any error messages... it's just saying that the page won't load. I use BBedit, and I'm not aware of any syntax error checker thingie, but will look into what you suggested.

Whoops ~ I realize what you mean about the authorship. I was a bit surprised by that, and assumed that I hadn't realized that I should be changing it... but obviously I misunderstood. I can easily change that back.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

One thing you could do to

One thing you could do to possibly help? is to output a message on halting the script

die("I have died cos the things that need to be defined 'true' don't appear to be ?")

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

If the page is saying it

If the page is saying it can't load then is it not a PHP error/problem? doesn't sound like it, have you just got a page path problem or not running your localhost server

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

Holy crap, Hugo ~ maybe it

Holy crap, Hugo ~ maybe it was all just a big karma problem, since I'd unwittingly changed the copyright info... I changed the authorship and copyright info (that doesn't display on the webpage, just what's seen on the script) back to what it should have been, with Chris' name and company info, and all of a sudden everything is working. Maybe he's got this thing rigged with some kind of techie voodoo. Wink

There's still a lot of work that I need to do, to get this thing sorted out 100%... I have to make it visually fit within the rest of my site and connect up to my main CSS page in particular, so I might be back in touch in regards to that if I have trouble. I'll have some fun digging around myself though, for starters.

One question though... when the e-mail arrived with the inquiry details, it first read "Submission/Inquiry received" with the date and time. The date is correct, but the time is off ~ I'm guessing this is most likely due to the fact that Chris is in the UK and I'm in Canada. Where abouts would I find this to fix?

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 20 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

The time is off by what?

The time is off by what? it's likely GMT or Unix time and probably stamped by the mailserver? or if set it's probably in the common.php file but you'll need Chris to take you through that.

and Chris is in Scotland I believe which barely counts as UK nowadays and is shortly to be severed from the mainland and floated off northwards

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

The time is three hours

The time is three hours earlier than it should be. On the e-mail itself the time is correct, but the inner info (client name and all that stuff the user filled out) is topped by date and time, in which the time is early. I'll see what Chris says when he returns to the forum and catches up on all this craziness.

I was in the UK last August for three weeks ~ England and Scotland. I was lucky enough to be there during a spell of unbelievably nice weather. Can't wait to go back. We've got family accommodations scattered all over both countries, and I've got flight benefits through my husband (pilot) so returning is easy. If I ever manage to run into either of you, the pints are on me.

A new problem I've discovered in my code...

I decided that rather than have all fields mandatory, I only wanted to have the ones marked with an asterisk. So I made some changes, but have since found that when the mandatory info is missing, the e-mail is still successfully sent. I've goofed something up, once again. :? I want to make "company name" and "website" optional, since some users might be people with new businesses. I believe any and all alterations were made on this page...

form.tpl.php:

" method="post">

For more information about our services, please fill out this form with details
of your inquiry. And don't worry... your information will not be given out to any
other party. All fields with an asterisk (*) must be completed.


<?php if (!empty($msg)) { ?>

Whoops! There was a problem processing your request, so please review
the messages below.



    <?php foreach ($msg as $text) { ?>
  • <?php echo $text; ?>

  • <?php } ?>

<?php } ?>
">
First name: *
" />

">
Last name: *
" />

">
Company:
" />

">
Phone: *
" />

">
E-mail: *
" />

">
Website:
" />

">
Inquiry details: *
<?php echo hsc($raw_more); ?>

" />

But you might want to look at these ones as well...

contact.php


<?php define('_JALAKAI_',true); include('include/contact.php'); ?>







Digital Paw Print: Unique and User-Friendly Web Design and Development



@import "../woof.css";

Contact Us

<?php if (empty($notification_success)) { ?>

Why not? You've got nothing to lose. Estimates are always free, and we're a friendly bunch. We'd love to hear from you.

<?php } else { ?>

Thank you for your interest in Digital Paw Print!
If you would like us to get in touch, please fully complete and submit the form below.

<?php } ?> <?php include('include/form.tpl.php'); ?>

include/contact.php:

<?php /* * contact us form processor script * * @original author christopher smith * @date 2007-06-25 * * (c)2007 Jalakai Designs */ if (!defined(_JALAKAI_) && !_JALAKAI_) die(); define('DEBUG',false); define('_DB_',false); define('_REDIRECT_',true); // for success - set to true to redirect, false to return to the same page // email addresses to receive notification of an inquiry $notify_addresses = array('[email protected]'); $notify_subject = '%s - Customer Inquiry'; // admin/support email address $email_admin = '[email protected]'; // email addresses from the following services will trigger an error, // the list will be used in a preg function, escape any special characters // use an empty array, "$banned_domains = array();" to exclude noone. $banned_domains = array('gmail','googlemail','hotmail','yahoo','aol'); // DB configuration if (_DB_) { define('_DB_CONNECTION_','db'); define('_DB_TABLE_','contact'); } if (_REDIRECT_) { $host = $_SERVER['HTTP_HOST']; $path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $page = 'thank_you.html'; // set to redirect page name $redirect_uri = "http://$host$path/$page"; } require_once (dirname(__FILE__).'/common.php'); require_once (dirname(__FILE__).'/functions.php'); $error = false; $msg = array(); global $highlight; $highlight = array(); $internal_error_msg = 'There was an internal error while processing your request. Please try again later. If the problem persists, please contact customer service at '.$email_admin.'.'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $raw_firstname = cleanInputString('first_name'); $raw_lastname = cleanInputString('last_name'); $raw_company = cleanInputString('company'); $raw_phone = cleanInputString('phone'); $raw_email = cleanInputString('email'); $raw_website = cleanInputString('website'); $raw_more = cleanInputString('more_info'); // create variables to hold data for insertion into the db and notification message text $insert = array(); $message = ''; if (empty($raw_firstname) && empty($raw_lastname)) { $error = true; $msg[] = 'Please provide your name.'; $highlight[] = 'first_name'; $highlight[] = 'last_name'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_firstname.$raw_lastname)) { $error = true; $msg[] = 'Illegal characters detected in name.'; if (preg_match('/[[:cntrl:]<>]/',$raw_firstname)) $highlight[] = 'first_name'; if (preg_match('/[[:cntrl:]<>]/',$raw_lastname)) $highlight[] = 'last_name'; } else { $insert['first_name'] = $raw_firstname; $insert['last_name'] = $raw_lastname; $message .= "Name: {$raw_firstname} {$raw_lastname}\n"; } // phone must exist if (empty($raw_phone)) { $error = true; $msg[] = 'The phone number is missing.'; $highlight[] = 'phone'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_phone)) { $error = true; $msg[] = 'Illegal characters detected in phone number.'; $highlight[] = 'phone'; } else { $insert['phone'] = $raw_phone; $message .= 'Phone: '.$raw_phone."\n"; } // email must exist, be valid & not be from banned domain list if (empty($raw_email) || !isValidEmail($raw_email)) { $error = true; $msg[] = 'The email address is missing or invalid.'; $highlight[] = 'email'; } else if (isBannedDomain($raw_email, $banned_domains)) { $error = true; $msg[] = 'The email address is from a public email service, please use a company email address.'; $highlight[] = 'email'; } else { $insert['email'] = $raw_email; $message .= 'Email: '.$raw_email."\n"; } if (empty($raw_more)) { $error = true; $msg[] = 'Please tell us the nature of your inquiry.'; $highlight[] = 'more_info'; } else if (preg_match('/[\x01-\x08\x0b\x0c\x0e-\x1f]/',$raw_more)) { $error = true; $msg[] = 'Illegal characters detected in Inquiry Detail.'; $highlight[] = 'more_info'; } else { $insert['more_info'] = $raw_more; $message .= "\nInquiry Detail\n==========================\n".$raw_more."\n"; } if (!$error) { if (_DB_) { require_once (dirname(__FILE__).'/mysql.class.php'); $db = new db(); $db->connect(_DB_CONNECTION_); $ok = $db->insert(_DB_TABLE_,array($insert)); } else { $ok = true; } // send notification email if (!empty($notify_addresses)) { // determine topic from calling page $topic = ucwords(strtr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4),'-_',' ')); $message = $topic."\n====================\n\n".$message; $notify_subject = sprintf($notify_subject, $topic); $from = "{$insert['name']} <{$insert['email']}>"; $mail_ok = notify($notify_addresses,$notify_subject,$from,$message); } if ($ok) { if (_REDIRECT_) { header("location: {$redirect_uri}"); exit(); } else { $notification_success = true; $raw_firstname = ''; $raw_lastname = ''; $raw_company = ''; $raw_phone = ''; $raw_email = ''; $raw_website = ''; $raw_more = ''; } } else { $error = true; $msg[] = $internal_error_msg; } } } else { $raw_firstname = ''; $raw_lastname = ''; $raw_company = ''; $raw_phone = ''; $raw_email = ''; $raw_website = ''; $raw_more = ''; }

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 35 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Hugo's right about Scotland

Hugo's right about Scotland floating off. If they have much more rain in Yorkshire, there will be a new sea.

If a field is not mandatory, remove the check for it's $raw_value being empty, just keep the checks for bad information.

You may also want to empty out the $banned_domains array.

Lambinastormtro...
Lambinastormtroopersuit's picture
Offline
Enthusiast
Canada
Last seen: 7 years 1 week ago
Canada
Timezone: GMT-4
Joined: 2006-06-02
Posts: 279
Points: 86

The error messages seem to

The error messages seem to come up okay, with just one problem... if I enter neither first name nor last name, then I receive an error message. But if I enter first name or last name, it goes through okay and I receive only one of the two names via e-mail. They are both supposed to be mandatory fields.

I'm pretty certain that the error is within the following code, I'm just having trouble locating it:

include/contact.php:

<?php /* * contact us form processor script * * @original author christopher smith * @date 2007-06-25 * * (c)2007 Jalakai Designs */ if (!defined(_JALAKAI_) && !_JALAKAI_) die(); define('DEBUG',false); define('_DB_',false); define('_REDIRECT_',true); // for success - set to true to redirect, false to return to the same page // email addresses to receive notification of an inquiry $notify_addresses = array('[email protected]'); $notify_subject = '%s - Customer Inquiry'; // admin/support email address $email_admin = '[email protected]'; // email addresses from the following services will trigger an error, // the list will be used in a preg function, escape any special characters // use an empty array, "$banned_domains = array();" to exclude noone. $banned_domains = array('gmail','googlemail','hotmail','yahoo','aol'); // DB configuration if (_DB_) { define('_DB_CONNECTION_','db'); define('_DB_TABLE_','contact'); } if (_REDIRECT_) { $host = $_SERVER['HTTP_HOST']; $path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $page = 'thank_you.html'; // set to redirect page name $redirect_uri = "http://$host$path/$page"; } require_once (dirname(__FILE__).'/common.php'); require_once (dirname(__FILE__).'/functions.php'); $error = false; $msg = array(); global $highlight; $highlight = array(); $internal_error_msg = 'There was an internal error while processing your request. Please try again later. If the problem persists, please contact customer service at '.$email_admin.'.'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $raw_firstname = cleanInputString('first_name'); $raw_lastname = cleanInputString('last_name'); $raw_company = cleanInputString('company'); $raw_phone = cleanInputString('phone'); $raw_email = cleanInputString('email'); $raw_website = cleanInputString('website'); $raw_more = cleanInputString('more_info'); // create variables to hold data for insertion into the db and notification message text $insert = array(); $message = ''; if (empty($raw_firstname) && empty($raw_lastname)) { $error = true; $msg[] = 'Please provide your name.'; $highlight[] = 'first_name'; $highlight[] = 'last_name'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_firstname.$raw_lastname)) { $error = true; $msg[] = 'Illegal characters detected in name.'; if (preg_match('/[[:cntrl:]<>]/',$raw_firstname)) $highlight[] = 'first_name'; if (preg_match('/[[:cntrl:]<>]/',$raw_lastname)) $highlight[] = 'last_name'; } else { $insert['first_name'] = $raw_firstname; $insert['last_name'] = $raw_lastname; $message .= "Name: {$raw_firstname} {$raw_lastname}\n"; } // phone must exist if (empty($raw_phone)) { $error = true; $msg[] = 'The phone number is missing.'; $highlight[] = 'phone'; } else if (preg_match('/[[:cntrl:]<>]/',$raw_phone)) { $error = true; $msg[] = 'Illegal characters detected in phone number.'; $highlight[] = 'phone'; } else { $insert['phone'] = $raw_phone; $message .= 'Phone: '.$raw_phone."\n"; } // email must exist and be valid if (empty($raw_email) || !isValidEmail($raw_email)) { $error = true; $msg[] = 'The email address is missing or invalid.'; $highlight[] = 'email'; } else { $insert['email'] = $raw_email; $message .= 'Email: '.$raw_email."\n"; } if (empty($raw_more)) { $error = true; $msg[] = 'Please tell us the nature of your inquiry.'; $highlight[] = 'more_info'; } else if (preg_match('/[\x01-\x08\x0b\x0c\x0e-\x1f]/',$raw_more)) { $error = true; $msg[] = 'Illegal characters detected in Inquiry Detail.'; $highlight[] = 'more_info'; } else { $insert['more_info'] = $raw_more; $message .= "\nInquiry Detail\n==========================\n".$raw_more."\n"; } if (!$error) { if (_DB_) { require_once (dirname(__FILE__).'/mysql.class.php'); $db = new db(); $db->connect(_DB_CONNECTION_); $ok = $db->insert(_DB_TABLE_,array($insert)); } else { $ok = true; } // send notification email if (!empty($notify_addresses)) { // determine topic from calling page $topic = ucwords(strtr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4),'-_',' ')); $message = $topic."\n====================\n\n".$message; $notify_subject = sprintf($notify_subject, $topic); $from = "{$insert['name']} <{$insert['email']}>"; $mail_ok = notify($notify_addresses,$notify_subject,$from,$message); } if ($ok) { if (_REDIRECT_) { header("location: {$redirect_uri}"); exit(); } else { $notification_success = true; $raw_firstname = ''; $raw_lastname = ''; $raw_phone = ''; $raw_email = ''; $raw_more = ''; } } else { $error = true; $msg[] = $internal_error_msg; } } } else { $raw_firstname = ''; $raw_lastname = ''; $raw_phone = ''; $raw_email = '';; $raw_more = ''; }

And aside from that, what do you make of the time issue that I mentioned above, Chris?