Solved

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

Posted on 2012-04-02
9
311 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make checkboxes execute queries on click 8 31
PHP SMTP authentication 6 24
curl parse data from site 20 38
A responsive image gallery using flexbox 6 19
These days socially coordinated efforts have turned into a critical requirement for enterprises.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

756 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