Jump to content

Recommended Posts

Hi guys,

 

I have a form for users to complete and when they press submit i will like the form to disappear and be replaced with a thank you message.

 

currently i have got it to display the thank message but this is displayed over the form, which is still visible.

 

Here is the code i need to change but i dont know how, this works by displaying either success or error message, i am currently showing you the code that displays success. Let me know if you would like to see all of the code.

 

.....
@ $db = new mysqli('localhost', 'root', 'DARREN', 'bulletins');

if (mysqli_connect_errno())
{
echo 'error';
}

$query = " INSERT INTO order_enquiries  (type, title, first_name, surname, position, company_name, company_email,  company_fax, company_telephone_number, address, address_1, address_2, address_3, town, county, post_code ) VALUES ('".$type."', '".$title."', '".$first_name."', '".$surname."', '".$position."','".$company_name."', '".$company_email."', '".$company_fax."','".$company_telephone_number."', '".$address."', '".$address_1."', '".$address_2."', '".$address_3."', '".$town."', '".$county."', '".$post_code."' )";
$result = $db->query($query);

$success .= "Your free sample will be dispatched as soon as possible.<br /><br />Please <a href=\"logout.php\" style=\"font-weight:bold;color:black;\">Logout</a>";


//need to add country, product and state
if ($success);

}
}			

 

kind regards

Dazzclub

Link to comment
https://forums.phpfreaks.com/topic/99338-after-the-form-has-been-submitted/
Share on other sites

Here is the code

 

<?php
session_start();
require_once '../includes/connection.php';
// check that the  user has logged in
if(isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] !== true || !isset($_SESSION['is_logged_in']))
{
    die('You must <a href="../admin/..">login</a> to view this page!');
}
// no need to query members table, query the contacts table as you already have the username in the 'user' session
$sql  = "SELECT * FROM contacts WHERE username='{$_SESSION['user']['username']}'";
// perform the query
$result = mysqli_query($connection, $sql);

// as you are only returning 1 row from the contact tables you don't need a while loop
$row = mysqli_fetch_assoc($result);
// display contact data for user
	$username = $row['username'];
	$type = $row['type'];
	$image = $row['image'];
	$title = $row['title'];
	$first_name = $row['first_name'];
	$surname = $row['surname'];
	$position= $row['position'];
	$company_name = $row['company_name'];
	$company_email = $row['company_email'];
	$company_fax = $row['company_fax'];
	$company_telephone_number = $row['company_telephone_number'];
	$company_fax = $row['company_fax'];
	$address = $row['address'];
	$address_1 = $row['address_1'];
	$address_2 = $row['address_2'];
	$address_3 = $row['address_3'];
	$town = $row['town'];
	$county = $row['county'];
	$post_code = $row['post_code'];


/////
if(isset($_POST['submit']))
{
$type=$_POST['type'];
$title=$_POST['title'];
$first_name=$_POST['first_name'];
$surname=$_POST['surname'];
$position=$_POST['position'];
$company_name=$_POST['company_name'];
$company_email=$_POST['company_email'];
$company_fax=$_POST['company_fax'];
$company_telephone_number=$_POST['company_telephone_number'];
$address=$_POST['address'];
$address_1=$_POST['address_1'];
$address_2=$_POST['address_2'];
$address_3=$_POST['address_3'];
$town=$_POST['town'];
$county=$_POST['county'];
$post_code=$_POST['post_code'];




$errors .= (empty($post_code)) ? "<span class=\"emptyFields\">We reuqire your postcode.</span>" : "";
$errors .= (empty($company_name)) ? "<span class=\"emptyFields\">We require a company name.</span>" : "";
$errors .= (empty($company_telephone_number)) ? "<span class=\"emptyFields\">We need your telepone number to contact you.</span>" : "";
$errors .= (empty($company_email)) ? "<span class=\"emptyFields\">To help you, we require your email.</span>" : "";


//need to add country, product and state
if (!$errors)
{
if(!get_magic_quotes_gpc())
{
$type = addslashes($type);
$title = addslashes($title);
$first_name = addslashes($first_name);
$surname = addslashes($surname);
$position= addslashes($position);
$company_name = addslashes($company_name);
$company_email = addslashes($company_email);
$company_fax = addslashes($company_fax);
$company_telephone_number= addslashes($company_telephone_number);
$address= addslashes($address);
$address_1= addslashes($address_1);
$address_2= addslashes($address_2);
$address_3= addslashes($address_3);
$town= addslashes($town);
$county= addslashes($county);
$post_code= addslashes($post_code);


}
@ $db = new mysqli('localhost', 'root', 'DARREN', 'bulletins');

if (mysqli_connect_errno())
{
echo 'error';
}

$query = " INSERT INTO order_enquiries  (type, title, first_name, surname, position, company_name, company_email,  company_fax, company_telephone_number, address, address_1, address_2, address_3, town, county, post_code ) VALUES ('".$type."', '".$title."', '".$first_name."', '".$surname."', '".$position."','".$company_name."', '".$company_email."', '".$company_fax."','".$company_telephone_number."', '".$address."', '".$address_1."', '".$address_2."', '".$address_3."', '".$town."', '".$county."', '".$post_code."' )";
$result = $db->query($query);

$success .= Thank you for completing the form.<br /><br/>Your free sample will be dispatched as soon as possible.<br /><br />Please <a href=\"logout.php\" style=\"font-weight:bold;color:black;\">Logout</a></span>";


//need to add country, product and state
if ($success);

}
}			
?>	
<!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">
<head>
<title>Complete the order form to recieve a free product</title>
<link rel="stylesheet" type="text/css" href="../styles/style.css" />
<head>
<body>
<div id="container">
<div id="holder">
<div id="header"><img src="../../images/banner.png" style="border:none;" /></div>
<div id="main">
<h3>Welcome <?php echo $username; ?><span style="color:red;"><?php echo ($errors) ? "<p class=\"errorSentence\">Some fields have not been completed: $errors</p>" : ""; ?></span>
 <span style="color:blue;"><?php echo ($success); ?></span></h3>
Are we displaying the correct contact details? If not please complete the from to update.
<br/><br/><br/>
<div class="orderFormContainer" >
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<ul class="orderForm">
	<li style="font-weight:bold;color:#666666;font-size:11pt;">ABOUT YOU</li>
	<li><input type="hidden" name="title" id="title" value="<?php echo $type; ?>"></li>
	<li>title: <input type="text" name="title" id="title" value="<?php echo $title; ?>"></li>
	<li>First name: <input type="text" name="first_name" id="first_name" value="<?php echo $first_name; ?>"></li>
	<li>Surname: <input type="text" name="surname" id="surname" value="<?php echo $surname; ?>"></li>
	<li>Position: <input type="text" name="position" id="position" value="<?php echo $position; ?>"></li>
	<li> </li>
	<li style="font-weight:bold;color:#666666;font-size:11pt;">ABOUT YOUR COMPANY</li>
	<li>Company name: <input type="text" name="company_name" id="company_name" value="<?php echo $company_name; ?>"></li>
	<li>Company email: <input type="text" name="company_email" id="company_email" value="<?php echo $company_email; ?>"></li>
	<li>Company tel: <input type="text" name="company_telephone_number" id="company_telephone_number" value="<?php echo $company_telephone_number; ?>"></li>
	<li>Company fax: <input type="text" name="company_fax" id="company_fax" value="<?php echo $company_fax; ?>"></li>
	<li>Address: <input type="text" name="address" id="address" value="<?php echo $address; ?>"></li>
	<li>Address 1: <input type="text" name="address_1" id="address_1" value="<?php echo $address_1; ?>"></li>
	<li>Address 2: <input type="text" name="address_2" id="address_2" value="<?php echo $address_2; ?>"></li>
	<li>Address 3: <input type="text" name="address_3" id="address_3" value="<?php echo $address_3; ?>"></li>
	<li>Town: <input type="text" name="town" id="town" value="<?php echo $town; ?>"></li>
	<li>County: <input type="text" name="county" id="county" value="<?php echo $county; ?>"></li>
	<li>Postcode: <input type="text" name="post_code" id="post_code" value="<?php echo $post_code; ?>" ></li>
	<li style="font-size:9pt;text-align:center;color:red;line-height:19px;font-weight:bold;">Now simply click submit <br/>to recieve a free sample</li>
	<li><input type="submit"  name="submit" value="submit"   title="submit" ></li>
</ul>
</form>
<img src="../../images/<?php echo $image; ?>"  class="image" title="Met Office Room Thermomemter"/>	
</div>

</div>
<div id="footer"></div>
<div>
</div>
</div>
</body>
</html>

 

kind regards

Darren

untested

 

See the two comments (*****added and *****modified)

 

 

<?php
session_start();
require_once '../includes/connection.php';
// check that the  user has logged in
if(isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] !== true || !isset($_SESSION['is_logged_in']))
{
    die('You must <a href="../admin/..">login</a> to view this page!');
}
// no need to query members table, query the contacts table as you already have the username in the 'user' session
$sql  = "SELECT * FROM contacts WHERE username='{$_SESSION['user']['username']}'";
// perform the query
$result = mysqli_query($connection, $sql);

// as you are only returning 1 row from the contact tables you don't need a while loop
$row = mysqli_fetch_assoc($result);
// display contact data for user
	$username = $row['username'];
	$type = $row['type'];
	$image = $row['image'];
	$title = $row['title'];
	$first_name = $row['first_name'];
	$surname = $row['surname'];
	$position= $row['position'];
	$company_name = $row['company_name'];
	$company_email = $row['company_email'];
	$company_fax = $row['company_fax'];
	$company_telephone_number = $row['company_telephone_number'];
	$company_fax = $row['company_fax'];
	$address = $row['address'];
	$address_1 = $row['address_1'];
	$address_2 = $row['address_2'];
	$address_3 = $row['address_3'];
	$town = $row['town'];
	$county = $row['county'];
	$post_code = $row['post_code'];


/////
if(isset($_POST['submit']))
{
$type=$_POST['type'];
$title=$_POST['title'];
$first_name=$_POST['first_name'];
$surname=$_POST['surname'];
$position=$_POST['position'];
$company_name=$_POST['company_name'];
$company_email=$_POST['company_email'];
$company_fax=$_POST['company_fax'];
$company_telephone_number=$_POST['company_telephone_number'];
$address=$_POST['address'];
$address_1=$_POST['address_1'];
$address_2=$_POST['address_2'];
$address_3=$_POST['address_3'];
$town=$_POST['town'];
$county=$_POST['county'];
$post_code=$_POST['post_code'];




$errors .= (empty($post_code)) ? "<span class=\"emptyFields\">We reuqire your postcode.</span>" : "";
$errors .= (empty($company_name)) ? "<span class=\"emptyFields\">We require a company name.</span>" : "";
$errors .= (empty($company_telephone_number)) ? "<span class=\"emptyFields\">We need your telepone number to contact you.</span>" : "";
$errors .= (empty($company_email)) ? "<span class=\"emptyFields\">To help you, we require your email.</span>" : "";


//need to add country, product and state
if (!$errors)
{
if(!get_magic_quotes_gpc())
{
$type = addslashes($type);
$title = addslashes($title);
$first_name = addslashes($first_name);
$surname = addslashes($surname);
$position= addslashes($position);
$company_name = addslashes($company_name);
$company_email = addslashes($company_email);
$company_fax = addslashes($company_fax);
$company_telephone_number= addslashes($company_telephone_number);
$address= addslashes($address);
$address_1= addslashes($address_1);
$address_2= addslashes($address_2);
$address_3= addslashes($address_3);
$town= addslashes($town);
$county= addslashes($county);
$post_code= addslashes($post_code);


}
@ $db = new mysqli('localhost', 'root', 'DARREN', 'bulletins');

if (mysqli_connect_errno())
{
echo 'error';
}

$query = " INSERT INTO order_enquiries  (type, title, first_name, surname, position, company_name, company_email,  company_fax, company_telephone_number, address, address_1, address_2, address_3, town, county, post_code ) VALUES ('".$type."', '".$title."', '".$first_name."', '".$surname."', '".$position."','".$company_name."', '".$company_email."', '".$company_fax."','".$company_telephone_number."', '".$address."', '".$address_1."', '".$address_2."', '".$address_3."', '".$town."', '".$county."', '".$post_code."' )";
$result = $db->query($query);

$success .= "Thank you for completing the form.<br /><br/>Your free sample will be dispatched as soon as possible.<br /><br />Please <a href=\"logout.php\" style=\"font-weight:bold;color:black;\">Logout</a></span>";


//need to add country, product and state
if ($success);

}
}else{ //*****MODIFIED			
?>	
<!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">
<head>
<title>Complete the order form to recieve a free product</title>
<link rel="stylesheet" type="text/css" href="../styles/style.css" />
<head>
<body>
<div id="container">
<div id="holder">
<div id="header"><img src="../../images/banner.png" style="border:none;" /></div>
<div id="main">
<h3>Welcome <?php echo $username; ?><span style="color:red;"><?php echo ($errors) ? "<p class=\"errorSentence\">Some fields have not been completed: $errors</p>" : ""; ?></span>
 <span style="color:blue;"><?php echo ($success); ?></span></h3>
Are we displaying the correct contact details? If not please complete the from to update.
<br/><br/><br/>
<div class="orderFormContainer" >
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<ul class="orderForm">
	<li style="font-weight:bold;color:#666666;font-size:11pt;">ABOUT YOU</li>
	<li><input type="hidden" name="title" id="title" value="<?php echo $type; ?>"></li>
	<li>title: <input type="text" name="title" id="title" value="<?php echo $title; ?>"></li>
	<li>First name: <input type="text" name="first_name" id="first_name" value="<?php echo $first_name; ?>"></li>
	<li>Surname: <input type="text" name="surname" id="surname" value="<?php echo $surname; ?>"></li>
	<li>Position: <input type="text" name="position" id="position" value="<?php echo $position; ?>"></li>
	<li> </li>
	<li style="font-weight:bold;color:#666666;font-size:11pt;">ABOUT YOUR COMPANY</li>
	<li>Company name: <input type="text" name="company_name" id="company_name" value="<?php echo $company_name; ?>"></li>
	<li>Company email: <input type="text" name="company_email" id="company_email" value="<?php echo $company_email; ?>"></li>
	<li>Company tel: <input type="text" name="company_telephone_number" id="company_telephone_number" value="<?php echo $company_telephone_number; ?>"></li>
	<li>Company fax: <input type="text" name="company_fax" id="company_fax" value="<?php echo $company_fax; ?>"></li>
	<li>Address: <input type="text" name="address" id="address" value="<?php echo $address; ?>"></li>
	<li>Address 1: <input type="text" name="address_1" id="address_1" value="<?php echo $address_1; ?>"></li>
	<li>Address 2: <input type="text" name="address_2" id="address_2" value="<?php echo $address_2; ?>"></li>
	<li>Address 3: <input type="text" name="address_3" id="address_3" value="<?php echo $address_3; ?>"></li>
	<li>Town: <input type="text" name="town" id="town" value="<?php echo $town; ?>"></li>
	<li>County: <input type="text" name="county" id="county" value="<?php echo $county; ?>"></li>
	<li>Postcode: <input type="text" name="post_code" id="post_code" value="<?php echo $post_code; ?>" ></li>
	<li style="font-size:9pt;text-align:center;color:red;line-height:19px;font-weight:bold;">Now simply click submit <br/>to recieve a free sample</li>
	<li><input type="submit"  name="submit" value="submit"   title="submit" ></li>
</ul>
</form>
<?php
//*****ADDED
}
?>
<img src="../../images/<?php echo $image; ?>"  class="image" title="Met Office Room Thermomemter"/>	
</div>

</div>
<div id="footer"></div>
<div>
</div>
</div>
</body>
</html>

 

 

ALSO

$success .= Thank you for completing the form.<br /><br/>Your free sample will be dispatched as soon as possible.<br /><br />Please <a href="logout.php\" style=\"font-weight:bold;color:black;\">Logout</a></span>";

 

should be (added a quote at the start)

$success .= "Thank you for completing the form.<br /><br/>Your free sample will be dispatched as soon as possible.<br /><br />Please <a href="logout.php\" style=\"font-weight:bold;color:black;\">Logout</a></span>";

 

 

EDIT:

should be

$success .= "Thank you for completing the form.<br /><br/>Your free sample will be dispatched as soon as possible.<br /><br />Please <a href=\"logout.php\" style=\"font-weight:bold;color:black;\">Logout</a></span>";

 

Also updated top top

Hi MadTechie,

 

This can actually work, the one thing i will need to look at closer is the error scripts as i dont feel this will show when i press submit.

 

I will look into it now and i will post back how i got on.

 

thanks for your help.

 

kind regards

Darren

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.