Old 11-27-2009, 12:59 AM   #1
angelwim
Registered User
text area in a form

Hi

I have successfully added kirupa's php contact form to a site. But now I want to modify it for a order page. As in the link i have given here ( pls have a look at the order page from the link below) I need to send a mail with the name of the product and quantity with the following details like name, email etc....

I am not sure how to add a text area into this PHP script. If anyone has some PHP knowledge in this pls help me. That would be greatly helpful since I am more of a designer.

thx

http://www.smlmats.com.au/html/order.html
angelwim is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-27-2009, 08:06 AM   #2
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
You can add a textarea into your HTML document easily enough with the <textarea> HTML tag, as I see you have done already. The important thing to take note of here is the value of the `name` attribute for the textarea, which you have to "comments".

When the form is submitted it is the `name` attributes that are used to reference the inputs provided by the form, regardless of what the input type is (be it a checkbox, textarea, combobox, etc.) In this case, then, PHP will look for the `comments` variable in the appropriate super global variable $_POST (note the `method="post"` in the <form> tag.)

What does that mean? It means that we can get the value of the textarea when we are in PHP by using the variable `$_POST['comments']` and to add this into the email we need simply do what we have previously for the other variables.

So you will have something like this:
PHP Code:
$message "Name: ".$_POST['name']."\nComments: ".$_POST['comments'];
// mail (... $message); 
Hope that helps
icio is offline   Reply With Quote
Old 11-27-2009, 09:28 AM   #3
angelwim
Registered User
Thanx for ur answer. But there is a bit confusion. Maybe I didnt explain it well. The main text area is fine. (I mean the "comment" variable)

What I dont know how to do is those small text boxes which the user can type for the number of quantities

for EX if the user select cow mat then he can tick the check box in front of it. then there is another text box for the quantitiy if u notice where they can type a number for how many cow mats they need. This is the area i dont understand. I need to send these information in a email as follows;

mat name
quantity

(I have omitted the obvious fields like name , email etc since that is working)

hope u get the point. and if u can work this around it would be great help. And also I can learn something new.

thanx again
angelwim is offline   Reply With Quote
Old 11-27-2009, 11:05 AM   #4
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Wow, that's not at all what you asked for in your original post. Edit: Oh, okay I think I see where you were coming from originally. But, no, it wasn't very clear.

The first thing that you need to do is make sure that the data in your products table is actually sent to the server when the form is submitted. To do this you need to include the inputs (ie. the checkboxes and quantity textfields) in the <form> tag. Based on your current HTML layout, if you move the <form> opening tag to just before <div id="ordertablewrapper"> I think this ought to work fine.

The next thing that you need to do is assign names to each of your inputs. For this I recommend using the array feature of names. That is you can submit multiple inputs under the same name, and it is treated as an array in PHP.

In this case you might want to use something like the following:
HTML Code:
Cow Mat: <input type="hidden" name="product[]" value="Cow Mat" /><input type="checkbox" name="order[]" /> (Quantity: <input type="text" name="quantity[]" />)
And the only thing that will change between products is the value of the hidden input, product[].

What we have here is three fields: the first is a hidden field which will send back the name of the product to the server, the second is a checkbox that will indicate in the submission that the product is to be ordered, and a third indicating the quantity of the product that ought to be ordered.

In PHP, when the form is submitted, you will have only three extra variables in $_POST: $_POST['product'], $_POST['order'] and $_POST['quantity']. The trick is that each of these variables is an array containing multiple pieces of information.

So, when it comes to reading the information you can do so like this:
PHP Code:
<?php
    
foreach ($_POST['product'] as $k => $product)
    {
        
$ordered = isset($_POST['order'][$k]);
        
$quantity $_POST['quantity'][$k];
        
        if (
$ordered)
        {
            echo 
"Ordered $quantity $product(s). ";
        }
        else
        {
            echo 
"Ordered no $product(s). ";
        }
    }
?>
Note here that we have explicitly typed the name of the product into the form and we are using that as our identifier. On more complex shopping systems what is actually put here is the ID number of the product. When the form is submitted information about the product, such as the name and cost, is taken from a database row selected based on the ID number. I felt that since your form is hard-coded in HTML that this was a neater way of handling the data.

Hope that helps
icio is offline   Reply With Quote
Old 11-29-2009, 06:55 AM   #5
angelwim
Registered User
one last bit

Hey Thanx a lot for helping me out my first PHP form. Sorry about putting it all wrong in the first post. Now I have implemented what u explained and it all seems to be getting there. but there is one more problem now. (Hopefully the last one)

When i press the submit button it gives me the correct message. Problem is with the e mail message. I dont know how to get it displayed in the mail message.( which is name of the order and the quantity)

And I dont know how to mix these new fields with my previous fileds like name , e mail and message. so I have pasted here the whole code. pls help me to solve this last bit. It ll really be helpful to upload this sooner.

this is how i have put it . and this is the link to the 'order' page with uploaded php script so far.

Thanx a lot

<?php
if(isset($_POST['submit'])) {

$to = "info@smlmats.com.au";
$subject = "Customer Inquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$body = "order: order\n product: $product\n quantity: $quantity";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "sorry..this e mail is not valid!";

}
?>

<?php
foreach ($_POST['product'] as $k => $product)
{
$ordered = isset($_POST['order'][$k]);
$quantity = $_POST['quantity'][$k];

if ($ordered)
{
echo "Ordered $quantity $product(s). ";
}
else
{
echo "Ordered no $product(s). ";
}
}
?>
angelwim is offline   Reply With Quote
Old 11-29-2009, 07:15 AM   #6
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Instead of echo'ing the status, simply append it to your $body variable once you've set the beginning of it.
icio is offline   Reply With Quote
Old 11-29-2009, 11:39 PM   #7
angelwim
Registered User
Quote:
Originally Posted by icio View Post
Instead of echo'ing the status, simply append it to your $body variable once you've set the beginning of it.

Please tell me how to write that. I have no clue. I tried to write like
'product:/n $product' but it doesnt work..

will You please tel me how to in code....

thank you
angelwim is offline   Reply With Quote
Old 11-30-2009, 08:09 AM   #8
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Put this
PHP Code:
foreach ($_POST['product'] as $k => $product)
    {
        
$ordered = isset($_POST['order'][$k]);
        
$quantity $_POST['quantity'][$k];
        
        if (
$ordered)
        {
            
$body .= "<br />\n$product: $quantity";
        }

After this
PHP Code:
$body "From: $name_field\n E-Mail: $email_field\n Message:\n $message"
Give that a try.
icio is offline   Reply With Quote
Old 12-02-2009, 08:15 AM   #9
angelwim
Registered User
hey that worked............great. THANX MAN

only thing is it gets the <br> tag after the quantity

its like this

cow mat:1
stable mat:1 <br>

but not an issue. i deleted the br tag and then i dont get the quantity displayed. if u can fix it that would be good. but still no problem.

thanx a lot again helping me out to sort this till the end.
appreciated.

angelwim is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:11 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com