Welcome to WebmasterWorld Guest from 107.20.59.213

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Change Location

     

peterinwa

8:07 am on Dec 10, 2013 (gmt 0)

10+ Year Member



I've used HTML and JavaScript for years and am finally trying PHP. There are a gazillion tutorials on the web telling you how to code a simple form on a webpage that sends the input in an e-mail.

The problem is that they all end up with a blank white screen and a PHP print message like: Form Sent

They all do that, but it's so lame. Who wants to end up with a black screen and no links! You should end up on a page of your website.

So I'm trying to direct it to the URL of one of my webpages, and inserted the code you see below. I understand it is failing because you can only use header location at the start of your php file. But you don't want to change the location before executing the php?

Thank you, Peter

<html><body>
<?php
$to="info@columbiariverpetpartners.org";
$subject="Membership Application";
$name=$_REQUEST['name'];
$FirstName=$_REQUEST['FirstName'];
$LastName=$_REQUEST['LastName'];
$FullName="$FirstName $LastName";
$message="First Name: $FirstName\nLast Name: $LastName";
$headers="From: $FullName";
$sent=mail($to,$subject,$message,$headers);
if ($sent) {header("Location: sent.html");
exit}
else {header("Location: failed.html");
exit}
?>
</body>
</html>

omoutop

9:50 am on Dec 11, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well, if you delete the <html><body> and </body></html> part your script will work

have your form post to a pure php page - no html there.
validate the fields
save to db
send email
at the end, if all are ok, use the header() to redirect to a thank you page (pure html page)

[edited by: omoutop at 9:54 am (utc) on Dec 11, 2013]

omoutop

9:53 am on Dec 11, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



alternative, since you are familiar with javascript (and perhaps some framework like jquery?) you can:

- submit form with ajax
- if success replace form container with a thank you message
- if failed, show error and keep form on page for user to correct

lucy24

11:26 am on Dec 11, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



You can keep the <html><body> et cetera if you make a page to go with it.

if (long string of conditions covering all the things that can go wrong with user input such as malformed e-mail address, missing text et cetera)
echo (wide array of messages telling human user they did something wrong)
else (pretty thank-you text)

and then the rest of your every-page boilerplate winding up with </body></html>

madjamesiam

12:01 pm on Dec 23, 2013 (gmt 0)



remove the html tags and save as a php page and validate the form using javascript or jquery if the credentials are valid then redirect to thank you message page or show thank you div using jquery before hide that div using jquery in same page, if the credentials are invalid show error message using jquery near to email textbox.
James mad
connected commerce
 

Featured Threads

Hot Threads This Week

Hot Threads This Month