Total newb: Need some help regarding forms

izihbo

New Member
Hello, this is my first post/thread here. I registered in hope to receive some help regarding a website I´m currently working on. I am not a pro, I can´t be considered a webMASTER :p

I make a hell of a mess - codewise - but in the end, it all looks good :D

My problem atm is; The customer wants to have this simple page, showing some products (15-20) with the ability to enter how many (amount) of each product people want to purchase.

Example:

[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]
[PRODUCT.JPG] - Text/information - [AMOUNT]

etc.

And at the bottom, they want a form where people can write their names, address, e-mail, phonenumber, etc. (with red stars to indicate required information, also an error message if people don´t fill it in)

Eventually a [SEND/Order now!] button - leading you to a new page saying "Thank you for your purchase, bla bla)

All this should generate a simple e-mail that will be sent to my client and he will handle the purchase manually from there.

This is like a webshop-light version i suppose and should be fairly easy to make.

- BUT NOT FOR ME. That´s why I´m asking here :) I have been googling for something similar - and sure - I find lots of things that could help, but I im the kinda guy who can look at a code - have everything I need - and still dont understand it.

Thanks for your time and I hope for some good answers! ;)

- Ronnie
 

conor

New Member
heres a form that sends an email that i wrote a while back. I have edited the info for your needs.

You can see it in action at http://macaoidh.name/work/order-form/

Code:
<div id="client_sales">
<?php
//start client sales

//set post variables
	$media_type	= $_POST['media_type'];
	$email		= $_POST['email'];

//settings for media_selected
function media_selected ($type) {

	global $media_type;

	if ($media_type == $type) { echo "selected"; }
}

//check if attempted
$attempted = ($_POST['attempted'] == 'yes');

if ($attempted) {

	$confirmed = (!empty($email) && !empty($media_type));

	if	(!$confirmed) {


	$malfunctions = '<p style="color:red;">Both \'email\', and \'product\' are required fields, please fill them in to complete your order.</p>';


	}
}

//check if attempted and confirmed
if ($attempted && $confirmed) {

	//send email

	$to = "[email protected]";
	$subject = "New Order on yoursite.com";
	$body = "Someone has ordered your product. <br />E-mail: $email <br />Product: $media_type. <br /> Goodbye :-)";
	$from = "From: [email protected]";

	$errors = 0;

	if (!$errors){

		if(mail($to, $subject, $body, $from)){
			echo("<h2>Thank You</h2><br />Thank You for ordering $product. You will recieve a comfirmation email once your request has been proccessed.");
		}
		else $errors+=1;
	}

	if ($errors){ 
	  echo("<h2 style=\"color:red\"> Sorry, there has been an error.</h2><p>To contact us manually and tell us about this problem, just follow the link below.</p><p><a href=\"mailto:[email protected]\">Contact us manually</a></p>");
	}
	
	  
}
//else display form
else{
	?>

							<form action="<?php echo $_SERVER['PHP_SELF'];?>#client_sales" method="POST">

							<h1>Order Product</h1>

							<p>Fill in the following details to complete your order.</p><br /><br />

							<?php echo $malfunctions; ?>

							<tr><td>E-mail:</td><td><input type="text" name="email" /></td></tr></table>

							<tr><td>Product:</td><td><select name="media_type">
									<option value="Choose One">Choose One</option>
									<option value="Product 1 - $20"<?php media_selected('product1'); ?>>Product 1 $20</option>
									<option value="Product 2 - $30" <?php media_selected('product2'); ?>>Product 2 - $30</option>
									<option value="Product 3 - $40" <?php media_selected('product3'); ?>>Product 3 - $40</option>
									<option value="Product 4 - $50" <?php media_selected('product4'); ?>>Product 4 - $50</option>
									<option value="Product 5 - $60" <?php media_selected('product5'); ?>>Product 5 - $60</option>
									</select></td></tr>

							<input type="hidden" name="attempted" value="yes" />

							<input type="submit" value=" <?php echo $attempted ? 'Continue Your Order' : 'Place Your Order' ; ?> " style="margin-left:250px;" />

							</form>	
	<?php
}
?>
 

izihbo

New Member
Hey thanks alot for your reply Conor.

Unfortunately the server where the website will be located does not (as far as I know!) support the PHP language.

I have been working on some ASP thing though, I´ve been using something that was already made by a friend of mine and modified it abit.


If you´re curious, you can check it out here:
http://www.dargan.no/bestilling/bestilling.html

Whatever you fill in, will be sent to my work-mail :p

My problem now is: How to put "required fills". Stuff like name, company name, address and e-mail will have to be required to fill, in order to complete the purchase...
 

conor

New Member
are you sure? Almost all hosts do support php. To check Create a new document with one line: <?php phpinfo(); ?>
Save it as test.php and then open it with your browser. It should return a page full of information. If not then php is not installed.

If you manage to get the example working then it does make both email and product required fields.

I just noticed that there are some unneeded trs and tds in there. It won't throw up any errors but of you want it to validate I advise getting rid of them.
 
Top