Solved

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

Posted on 2012-04-02
9
306 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
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 108

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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 108

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 108

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 108

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now