473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding a redirect after submission, not sending if user does not agree

2
Hello, I am pretty new to PHP, and I had gotten a friend to help me write a php form.

I have everything set how I need it to be, but I am missing a few important things.

Users can just hit submit, and a blank message will be sent. I also have an agreement checkbox, which users can ignore, as the message will send even if it is not checked. Lastly, I need the page to display a "success message" when they hit submit.

Here is the code I have so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
if($_POST['emailSub']) {
$to = "baftub@gmail.com";
$subject = "Blog Application";
$message = "Firstname:\t" . $_POST['firstname'] .
"\nLastname:\t" . $_POST['lastname'] .
"\nEmail:\t" . $_POST['email'] .
"\nitem:\t" . $_POST['item'] .
"\ncomment:\t" . $_POST['comment'];
mail($to, $subject, $message);
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Content Submission</title>
<style type="text/css">
<!--
body {
background-color: #121212;
}
body,td,th {
color: #FFF;
}
-->
</style></head>

<body>
<center>Please fill out this form for any content you wish to contribute
<br />
<br />
<br />
<form name="input" action="" method="post">
First name:
<input type="text" name="firstname" />
<br />
<br />
Last name:
<input type="text" name="lastname" />
<br />
<br />
Email:
<input type="text" name="email" />
<br />
<br />
Which item are you going to contribute to?
<input type="text" name="item" />
<br />
<br />
Please provide further details for your submission, any pictures or files.
<br />
<textarea cols="50" rows="4" name="comment"></textarea>
<br />
<br />
I agree that content submitted by myself is created by me, and does not breach any copyrights
<br />
<input type="checkbox" name="yes" value="yes" />
<br />
<br />
<input type="submit" name="emailSub">
</form>
</center>
</body>
</html>

Thank you for the help :)
Jul 5 '10 #1
3 1770
TheServant
1,168 Expert 1GB
Welcome to Bytes. I have read through your message and I don't see your question? What is not working?
Jul 5 '10 #2
BAFTUB
2
@TheServant
I do not know how to add a redirect after the user hits submit. I do not know how to add a success message after it is sent, and I do not know how to force them to agree to the terms, or else they cant submit it.
Jul 5 '10 #3
TheServant
1,168 Expert 1GB
Sure. Well you don't need to "redirect after a user submits". In your form you have action="". You if you put the current page's URL in that, then it will submit the form data to that page and do what I think you're after. You can also put another page URL which will look at the data and display the response.

The mail() function returns a success or fail response, so you can do something like:
Expand|Select|Wrap|Line Numbers
  1. if(mail($to, $subject, $message)) {
  2. echo "Success";
  3. } else {
  4. echo "Fail";
  5. }
Instead of echo, you can set a variable to the message and call that further down in a more appropriate HTML spot.

With regards to forcing them to check a box, you can put in another message system:
Expand|Select|Wrap|Line Numbers
  1. if($_POST['yes']=="yes") {
  2. //send email
  3. } else {
  4. echo "You must accept the terms and conditions to continue";
  5. }
As I say, instead of echo, set a variabel to the message and then call that variable in a pack you want your messages displayed in the HTML.

Oh, and that is all a PHP solution, which is probably best, but you can use javascript to give the user feedback on the form as well, and in the future you should look at that.
Jul 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Lowe | last post by:
I'm using Forms authentication with my user data in a SQL db. I have pages in the main appliaction folder accessible to anonymous users and I've set security to deny annonymous users access to...
2
by: Nathan Sokalski | last post by:
I am using the Response.Redirect method in a User Control to allow visitors to click an ImageButton to take them to another page. However, when I click the ImageButton I recieve the following...
1
by: Sally Sally | last post by:
I was wandering how I can add a user to a specific db. There are several databases but I want to add the user to only one of them. It seems when I add a new user, it is entered in the pg_user table...
1
by: kalaivanan | last post by:
hi, I am getting the following error while trying to add a remote server. The user does not have permission to perform this action. The command i used is: exec sp_addlinkedserver...
1
by: Chris | last post by:
Hi, i created a default page with loginview and loginstatus like this: <asp:LoginView ID="LoginView1" runat="server"> <LoggedInTemplate>You are logged</LoggedInTemplate>...
2
by: smartchap009 | last post by:
hi, If i can get help in writing perl code for adding updating and deleting user in linux.adds a user to the database file called passwd. With the -a switch the program accepts a user-id and...
1
by: smartchap009 | last post by:
Adding,Updating and Deleting user using perl script in linux -------------------------------------------------------------------------------- hi, If i can get help in writing perl code for...
5
by: jdserran | last post by:
i need help, this is my code for my form: print header; print start_html('Assignment 2'), start_form(-action=>'lwpmsample.pl',-method=>'POST'), "Option: ",...
4
by: suganya | last post by:
Hi By getting the email id from txtEmailId, I have to send the user name & password to that particular email id. For that on button click event I have given the coding as Protected Sub...
1
by: ashdaredevil | last post by:
when i am addind a database file to project as data source sql server database file the following error generated error: user does not have permission to perform this action please help me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.