Solved

Problem: My contact.php does not automatically re-direct to my website

Posted on 2012-04-02
9
317 Views
Last Modified: 2012-04-07
I was just wondering if there is anyway I can possibly change the way my contact.php is currently working. At the moment when someone fills up the form on my website they are left with a blank page with a 0 in the top left hand corner, and it really deteriorates the presentation value of the site. What I am looking for is to make the contact.php form do its process but afterwards have it redirect to another page on my website instead of simply sitting on that blank page.

Here is the script I am currently using for my contact.php form:

?php // contact.php
error_reporting(E_ALL);

// ACTIVATE THESE TWO LINES TO SEE THE POST INFORMATION
// echo "<pre>";
// var_dump($_POST);

// THE EMAIL ADDRESS THAT WILL RECEIVE THE MESSAGE
$m = 'info@deconlogic.com';

// A FUNCTION TO CLEAN UP THE INFORMATION AND AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $rgx
    = '#'         // REGEX DELIMITER
    . '['         // CHARACTER CLASS
    . '^'         // NEGATION - MATCH NONE OF THESE ACCEPTABLE CHARACTERS
    . ' A-Z0-9_,?/@&*=()!\.\-'
    . ']'         // END OF CHARACTER CLASS
    . '#'         // REGEX DELIMITER
    . 'i'
    ;

    // ELIMINATE EXCESS WHITESPACE
    $str = trim(preg_replace('#\s\s+#', ' ', $str));

    // RETURN THE STRING - BAD CHARACTERS REPLACED WITH THE QUESTION MARK
    return preg_replace($rgx, '?', $str);
}

// CLEAN AND FORMAT THE INFORMATION
$n = clean_string($_POST['n']);
$p = clean_string($_POST['p']);
$e = clean_string($_POST['e']);
$t = clean_string($_POST['t']);

$w = $_SERVER["HTTP_HOST"];

// CREATE THE EMAIL MESSAGE
$b = <<<MESSAGE
Name: $n
Phone: $p
Email: $e
Job Description: $t
MESSAGE;

// SEND THE MESSAGE
mail($m, "Message from $w", $b);

Open in new window


And this is a link to the page which is using this.

Decon - Contact Page

Hopefully someone can help me out, this is thanks in advance.
0
Comment
Question by:Ted1984
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 17

Expert Comment

by:selvol
ID: 37799479
PUT this on top of the <body>
<SCRIPT type="text/javascript">
 function goToPage(url)
 {
 var initial = "http://www.page yuou want.com";

 document.something.action=initial;
 }
 </SCRIPT>
Chage you form with this line.
<form method="post" action="contact.php" id="contact-form" onsubmit="goToPage(this.url.value);">

 <INPUT type="text" name="url" value="">
 <INPUT type="submit" value="GO">
 </FORM>
 </BODY>
 </HTML>
0
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37800413
If you want to redirect to another page, put this line at the end of the script:

header('Location: http://www.deconenviro.com/');

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37800827
You do not need to redirect the client browser.  You can, but it is not necessary.  After line 48 (sends the email message) you can just create a "thank you" page, something like this using heredoc notation.  It can be as simple or elaborate as you would like.  You can load the page via include() or put the HTML string into the contact.php page.
$html = <<<HTML
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<!-- ... REST OF THE HTML PAGE GOES HERE -->
HTML;

echo $html;

Open in new window

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:Ted1984
ID: 37814983
Should this work?

<?php // contact.php
error_reporting(E_ALL);

// ACTIVATE THESE TWO LINES TO SEE THE POST INFORMATION
// echo "<pre>";
// var_dump($_POST);

// THE EMAIL ADDRESS THAT WILL RECEIVE THE MESSAGE
$m = 'info@deconlogic.com';

// A FUNCTION TO CLEAN UP THE INFORMATION AND AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $rgx
    = '#'         // REGEX DELIMITER
    . '['         // CHARACTER CLASS
    . '^'         // NEGATION - MATCH NONE OF THESE ACCEPTABLE CHARACTERS
    . ' A-Z0-9_,?/@&*=()!\.\-'
    . ']'         // END OF CHARACTER CLASS
    . '#'         // REGEX DELIMITER
    . 'i'
    ;

    // ELIMINATE EXCESS WHITESPACE
    $str = trim(preg_replace('#\s\s+#', ' ', $str));

    // RETURN THE STRING - BAD CHARACTERS REPLACED WITH THE QUESTION MARK
    return preg_replace($rgx, '?', $str);
}

// CLEAN AND FORMAT THE INFORMATION
$n = clean_string($_POST['n']);
$p = clean_string($_POST['p']);
$e = clean_string($_POST['e']);
$t = clean_string($_POST['t']);

$w = $_SERVER["HTTP_HOST"];

// CREATE THE EMAIL MESSAGE
$b = <<<MESSAGE
Name: $n
Phone: $p
Email: $e
Job Description: $t
MESSAGE;

// SEND THE MESSAGE
mail($m, "Message from $w", $b);

$html = <<<HTML
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<!-- ... deconenviro.com/formsent2.html -->
HTML;

echo $html;

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37816226
Line 53 is an HTML comment.  I think you might want to read the HTML file deconenviro.com/formsent2.html into a string variable and put that variable in place of the comment.
0
 

Author Comment

by:Ted1984
ID: 37818264
I'm unsure how to turn it into a string variable, is there anyway you can help me with a script? I honestly know nothing about .php or just about any script for that matter, since you can tell I am even scared to remove your descriptions from the code itself.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37818601
If you don't know PHP but you're trying to write a PHP script, you might as well be trying to write German poetry without knowing German language.  The outcomes are likely to be suboptimal.

You might want to consider hiring a professional to help with this.  If you believe, as I do, that time is money you will undoubtedly find that you can exchange a very little money for a great saving of time.  It's not a scary thing at all; you just need some assistance from someone who is familiar with the languages.  ELance.com is a source for freelance professionals, and I have heard that EE now has a "hire me" section.
0
 

Author Comment

by:Ted1984
ID: 37818858
If I had the money to hire freelancers then I wouldn't be trying to do it myself, or come to a website such as this.

Now if you must know PHP is not poetry, it's not even right to call it a language, at most we can call it a system of grammar, defined by coding which is something so simple you can learn it over night as I just have, but you my friend will not learn poetry in a lifetime.

Now if I had to do PHP in the German Language, it would still not be as complicating as poetry.

Thank you for your help but you've repelled me from continuing a subscription past my trial, and directed me to the web to find my answers.

And in search I found this website and learned all I need to know.

Eureka!
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37819624
Thank you for sharing, Ted1984.  I assumed, apparently incorrectly, that this site was something with economic value and a sponsoring organization that was paying for site development.  And I was quite serious when I said "a very little money."  I'm talking about buying someone a beer, and the thing is all done before the beer is gone.

Tizag is a good site, as is W3Schools.  However they do not have a question and answer dialog like we have here at EE.  The script you posted with the question is one that I wrote.  It's not intended to be a finished product; it is only a teaching example.  You may have figured that out, but as Alexander Pope says, "A little learning is a dangerous thing."  Please don't confuse ignorance with a lack of intelligence.  There are lots of smart people who do not know HTML or PHP (I teach many of them, and it's always a pleasure to see the "lightbulb" go on).  If you knew PHP and HTML you would have implemented the principles shown at ID: 37800827.

In case you ever decide you want to take on some structured learning, this book will help you get a foundation.  Very readable with excellent examples.  Now in its fourth printing, it's been a permanent part of my professional library since Edition One.
http://www.sitepoint.com/books/phpmysql4/

Good luck with your project, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question