Jump to content

D3158

Recommended Posts

Basically I've a Contact Form where a user fills in Name, Email Address and Comments and then there is aSubmit button. If I just hit "Submit" without filling in anything or wrong information, it takes me to this page,send_form_email.php. This page has all the validators in it. I want it to sort of (I say sort of because I still need to check whether they input everything correctly) bypass this page and go to "submitted-contact.php" page (it's going to this page but its not showing the following as specified in the 2) where it displays one of the 2 things: 1) Login Success 2) Try Again!

 

Right now, there's nothing showing. :|

 

send_form_email.php has this at the very top and it calls header location to the page, submitted-contact.php

 

SEND_FORM_EMAIL CODE

[/b]


[b]<?php
session_start();
$_SESSION['error']=true;
$_SESSION['error']=false;
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "blah@hotmail.com";
$email_subject = "Your email subject line here";


function died($error) {
// your error code can go here
echo $error;
die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('');
}

$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$sendit= @mail($email_to, $email_subject, $email_message, $headers);
if($sendit){
header('Location:submitted-contact.php');
}else{echo "Email failed to send";}
}
?>

 

 

SUBMITTED-CONTACT.PHP CODE

<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><style type="text/css"></style>
<title>CKK Internet Marketing</title>
<link href="style.css" rel="stylesheet" type="text/css" media="all">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lato">
<link rel="shortcut icon" href="images/favicon.ico" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/jquery.sticky.js"></script>
<script src="js/jquery.cycle.all.js"></script>
<script src="js/jquery.smoothscroll.js"></script>

<script>
$(document).ready(function(){
$(".navigation").sticky({topSpacing:0});
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27381915-2']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>

<body class="submitted">

<div class="navigation">
<div class="container">
<a href="#"><img src="images/logo.png"</a>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About Us</a></li>
<li><a href="/service">Services</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/index.html#contact">Contact</a></li>
</ul>
</div>
</div>

<div id="submitted-content-2">
<div class="content container">
<?php
if (!isset($_SESSION['flunk'])){
$myString = "MESSAGE FLUNKED!";
echo $myString;
}else (!isset($_SESSION['pass'])){
$myString2 = "MESSAGE PASSED!";
?>
<div class="clear"></div>

</div>
</div>

</div>


<div class="clear"></div>

<div class="footer">
<div class="container">

</div>
</div>

</body>


</html>

 

 

The php code in submitted-contact.php, the following code is in the right location but just the wrong syntax?

<div id="submitted-content-2">

<div class="content container">

<?php

if (!isset($_SESSION['flunk'])){

$myString = "MESSAGE FLUNKED!";

echo $myString;

}else (!isset($_SESSION['pass'])){

$myString2 = "MESSAGE PASSED!";

?>

<div class="clear"></div>

</div>

</div>

</div>

 

 

Basically, I want to commute from send_form_email.php to submitted-contact.php one of the two things:

1) If user inputted everything well on the Contact Page, show them, "You're logged in"

2) If user inputted wrong information or did not fill in everything on the Contact Page, show them, "Try Again"

 

I want that to be shown withing my <div class="content container">

 

Sorry, I know this was a long post but I really could use a hand on this. I have been trying to figure this out for the past couple of days! :|

 

Thanks guys

D3158

Edited by D3158
Link to comment
Share on other sites

You forgot to start the session on the submitted-contact.php page, so just call session_start() and I think it might work. I have not looked through the rest of your code, because it was so much and I almost instantly had an idea what it might be.

It might be a good idea to turn on errors and warnings in your PHP installation. You can do this in the php.ini file. Then it would have shown a warning I think, or maybe even an error, I am not sure, but I do know that it would have said something.

Edited by Langstra
Link to comment
Share on other sites

Thanks. WIll try it. Also, I don't need to call $_SESSIONS in my submitted-contact.php to make it work also? :\

 

EDIT: Even though I added session_start(), to my submitted-contact.php file at the very top, it doesn't work. I know it's a lot of code but I'd really appreciate it if you (Langstra) can read the entire thing and provide me with pointers and/or solution on why it doesn't work. It's so bothering me. :|

Edited by D3158
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.