homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Change Location
peterinwa

10+ Year Member



 
Msg#: 4629197 posted 8:07 am on Dec 10, 2013 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4629197 posted 9:50 am on Dec 11, 2013 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4629197 posted 9:53 am on Dec 11, 2013 (gmt 0)

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

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



 
Msg#: 4629197 posted 11:26 am on Dec 11, 2013 (gmt 0)

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



 
Msg#: 4629197 posted 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved