Jump to content

Mailform with count++ function for products help needed


The_Dude_1978

Recommended Posts

 

Hi Guy's,

 

I need help with a form, where I got the mail form almost complete. I only need to send the item1, item2, item3 etc with the mail form.

Now it only show's the first product on receiving mail because it needs a count++ code, but I don't know how to add it.

 

<?php
session_start();
require_once '_php/config.php';
include('_php/functions.php');
?>
<?php 
$recipient = 'info';
$host = 'localhost';
$your_email = $recipient . '@' . $host; 

$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';
$username = '';
$Subtotal = '';
$Tax = '';
$Total = '';
$Item = '';

if(isset($_POST['submit']))
{
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
$username = $_SESSION['username'];
$Subtotal = $_POST['Subtotal'];
$Tax = $_POST['Tax'];
$Total = $_POST['Total'];
$count = 1;
$Item = $_POST['item_name_'.$count.''];
$count++;

///------------Do Validations-------------
if(empty($name)||empty($visitor_email))
{
	$errors .= "\n Naam en e-mail adres zijn vereist. ";	
}
if(IsInjected($visitor_email))
{
	$errors .= "\n Het e-mailadres is onjuist! ";
}
if(empty($_SESSION['6_letters_code'] ) ||
  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
	$errors .= "\n De Captcha code komt niet overeen! ";
}

if(empty($errors))
{
	//send the email
	$to = $your_email;
	$subject="$name wil foto's bestellen";
	$from = $your_email;
	$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

	$body = "$name wil de volgende foto's bestellen: \n".
	"Naam: $name\n".
	"E-mail: $visitor_email \n".
	"Bericht: \n ".
	"$user_message\n".
	"IP: $ip\n".
	"Gebruikersnaam: $username \n".
	"Item(s): $Item \n".
	"Subtotaal: $Subtotal \n".
	"BTW: $Tax \n".
	"Totaal: $Total \n";

	$headers = "From: $from \r\n";
	$headers .= "Reply-To: $visitor_email \r\n";

	mail($to, $subject, $body,$headers);

	header('Location: success.php');
}
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!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>

<meta http-equiv="content-Language" content="nl">
<meta http-equiv="imagetoolbar" content="no">
<meta name="language" content="NL">
    <meta name="keywords" content="">
<meta name="description" content="">
<meta name="copyright" content="M.A. Kamminga">
    <meta name="author" content="M.A. Kamminga">
    <meta name="publisher" content="M.A. Kamminga">
    <meta name="language" content="NL">
    <meta name="charset" content="ISO-8859-1">
    <meta name="distribution" content="Global">
    <meta name="rating" content="General">
    <meta name="expires" content="never">
    <meta name="robots" CONTENT="index,follow">
    <meta name="revisit-after" CONTENT="2 days">
<meta name="geo.placename" content="Zwolle (Overijssel), Nederland" />
    <meta name="geo.position" content="52.538174;6.057053" />
    <meta name="geo.region" content="NL-Overijssel" />
    <meta name="ICBM" content="52.538174,6.057053" />
    <meta name="geo.country" content="NL" />

<SCRIPT TYPE="text/javascript"> 
var message="Disabled"; 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu=new Function("return false") 

</SCRIPT> 
<title>Foto's bestellen ...</title>
<!-- define some style elements-->
<!--[if IE 6]>
<style type="text/css">
#contact p {
padding-top: 10px;}
</style>
<![endif]-->
<!--[if IE 7]>
<style type="text/css">
#contact p {
padding-top: 10px;}
</style>
<![endif]-->
<link href="style.css" rel="stylesheet" type="text/css">
<link href="contact.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="_style/main.css" />
<script src="_scripts/functions.js"></script>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body id="contactopnemen">
<div id="vertical">
<div id="wrapper">
<div id="header">
<?php include('../header_sub.php'); ?>
</div>
<div id="content_index">

<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id="form">
<div id='contact_form_errorloc' class='err'></div>
<h3>Wilt u het totaalbedrag overmaken op rekeningnummer: <font color="red"/> 748209697</font> ten name van: N Timmerman te Zwolle</h3>
<p> 
<?php
if($_SESSION['id'])
echo " <a href=\"profile.php?username=".$_SESSION['username']."&id=".$_SESSION['id']."\">Terug naar de Fotosheet(s)</a>";
else
{
echo "<a href=\"index.php\">U bent reeds uitgelogd, klik hier om weer in te loggen</a>" ;

}
?>
</p>
<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<div id="container">
	<h2>Overzicht bestelling:</h2>

	<h5><?php mailShoppingCart() ?></h5>
</div>
<h5><font color="red"/>Voor de bestelling hebben wij uw gegevens nodig. Gelieve deze hier in te vullen: </font></h5>
<p>
  <label for='name'>Naam: </label>
  <br>
  <input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
  <label for='email'>E-mail: </label>
  <br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>

<label for="afleveren"><h3>Aflever methode</h3></label>
<p>	<input type="radio" name="afleveren" value="post" checked />Bezorgen via post
<input type="radio" name="afleveren" value="afhalen" /> Afhalen</p>
<p>
<label for='message'>Aanvullende opmerkingen:</label> <br>

<textarea name="message" rows=9 cols=50><?php echo htmlentities($user_message) ?></textarea>
</p>

<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br><br>
<label for='message'>Type bovenstaande code over:</label><br>
<input id="6_letters_code" name="6_letters_code" type="text">	
  <input type="submit" value="Verzend" name='submit'>
<br>
</p>
<p>
<small><a href='javascript: refreshCaptcha();'>Kun je de afbeelding niet lezen? Klik hier voor een andere</a> </small>
</p>


</form>
</div>
</div>
<div id="footer">  
<?php include('../footer_sub.php'); ?>
</div>
</div>
</div>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Geef aub je naam op"); 
frmvalidator.addValidation("email","req","E-mail adres is verplicht"); 
frmvalidator.addValidation("email","email","E-mail adres moet valide zijn"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>

 

This is the current output while i've also selected a photo called Foto 1 apart from the photo test

 

test wil de volgende foto's bestellen: 
Naam: test
E-mail: test@test.com 
Bericht: 
test
IP: ::1
Gebruikersnaam: test 
Item(s): test 
Subtotaal: €12.60 
BTW: €2.39 
Totaal: €14.99 

 

Kind regards,

 

Martijn, The Netherlands

Link to comment
Share on other sites

 

Hi again,

 

Maybe i'm not describing it clear enough.

When I select 2 photo's or more, I want to output the results to a variable in the mailform, but I only can send 1 product at the moment. Other selected products don't come along.

 

This is the function I call

 

function mailShoppingCart()
{

//Function creates the display for the cart

//If the cart exists then follow on
if(cartExists())
{

	//Check if there are any products in the cart by counting the array keys
	if(count($_SESSION['paypalCart']) > 0)
	{

		//The table header html
		$html = '
		<table cellpadding="0" cellspacing="0" border="0">
			<tr>
				<th>Thumbnail</th>
				<th>Item naam</th>
				<th>Prijs</th>
				<th>Hoeveelheid</th>
				<th></th>
			</tr>
		';

		$count = 1;

		//Loop through the items in the paypal cart
		foreach($_SESSION['paypalCart'] as $product)
		{

			$html .= '
			<tr>
				<td width="250"><img src='.$product['username'].'/pics/thumbs/'.$product['thumbnail'].'></td>
				<td width="200">'.$product['name'].'</td>
				<td width="200">€'.number_format($product['price'], 2).'</td>
				<td width="250">'.$product['qty'].'</td>

				<input type="hidden" name="amount_'.$count.'" value="'.$product['price'].'" />
				<input type="hidden" name="quantity_'.$count.'" value="'.$product['qty'].'" />
				<input type="hidden" name="tax_rate_'.$count.'" value="'.TAX.'" />
				<input type="hidden" name="item_name_'.$count.'" value="'.stripslashes($product['name']).'" />
				<input type="hidden" name="item_number_'.$count.'" value="'.$product['item'].'" />
			</tr>
			';

			$count++;

		}

		//HTML for the subrows such as the subtotal, tax and total
		$html .= '
			<tr class="empty">
				<td></td>
				<td></td>
				<td></td>
				<td></td>

			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">Subtotaal</td>
				<td>'.calculateSubtotal().'</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">'.TAX.'% BTW</td>
				<td>'.calculateTax().'</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">Totaal</td>
				<td>'.calculateTotal().'</td>
			</tr>

		</table>



		';

		echo $html;

	}
	else
	{

		//If there are no products then print out a message saying there are no products
		echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>';
		unset($_SESSION['paypalCart']);
	}

}
else
{

	//If there are no products then print out a message saying there are no products
	echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>';
	unset($_SESSION['paypalCart']);
}

}

 

So what i need is to fetch the <input type="hidden" name="item_name_'.$count.'" value="'.stripslashes($product['name']).'" />

with a foreach (i'm thinking later, instead of the ++ function?)

and put that in a variable which I can send out via the mail form.

 

Please help me! I've tried, but i'm stuck.

 

Kind regards,

 

Martijn

Link to comment
Share on other sites

I'm not giving up!

 

I've came across a website that mails the $_SESSION.

 

So i did and I get Array as result:

 

test wil de volgende foto's bestellen: 
Naam: test
E-mail: test@test.com 
Bericht: 
test
IP: ::1
Gebruikersnaam: test 
Items: Array 

 

How do I get my ordered products in my mail confirmation?

 

Kind regards,

 

Martijn

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.