Jump to content

Advanced Forms


jadiebrown

Recommended Posts

I know how to code a contact form into a page. I am also comfortable with writing the .php document to action the email to be sent from the form. However, my knowledge is basic. The fields I have used are Name, Email, Message and Subject. I would like to develop this into something quite a bit more advanced. Does anyone have any input to assist with these enhancements?1. The company sells products that are advertised online. Each product has a unique code (e.g. A092). Next to each product is a link titled "more info". I would like this link to open up a contact form that holds the product's unique code in the subject line. Obviously I can code a seperate form for each product that goes onto the site, but that is really a slow way around. Is it possible to automate the code so that the form will automatically determine which product the user has linked from and insert that code into the subject line?2. I want to create an Purchase Order Form. Just like the standard contact form, the name, email and message fields will be used. However, the subject will obviously be standard - Purchase Order. I would like to add additional fields to the form though and I am not sure how to write the .php file to incorporate all the additional fields. Would I use the "headers" element? If so, how would I do so? The link to this form would come from a specific product so, again I would want to unique code to be incorporated somewhere. One of these additional fields would be a radio button confirming that the user has read the Terms and Conditions so that would need to come up as well. This form would then need to be emailed to me as with the others.3. The last enhancement would be to create a form with which the user can advertise his/her own product on the site. This form would be a contact form with various additional fields. However, the main issue here is that I would like the form to have the capacity for the user to attach images of their product.I realise that I am asking quite a bit. But, I think that the fact that I understand the basics of the form-post-php process will make it pretty simple for me to jump to this next phase. I would really appreciate any help with one or all of these enhancemetns.

Link to comment
Share on other sites

One step at a time.1. Check out the $_GET variable as a Query String in a link tag. You will need to be using a server-side scripting language such as php.Adding the 'product code' to the Anchor tag is easy. Instead of :

<a href="contact.php">

Use :

<a href="contact.php?pc=A209">

as the link. Then, the contact form will need to search the $_GET array to see what pc=product_code is being sent and handle the contact form accordingly.2. For the Purchase Order form, I suggest using the method = "post". There are tutorials on the w3schools site about that. Look in the php section. Similar to above, the Script needs to check for the $_POSTed array and use the information to build the message body. While you are at it, the information can be stored into a database for future retival of the information to chenge it from a Purchase Order to 'sold order' or something along those lines.3. Now you will need two things. First, an Upload script to supply the Image(s) and then a form for the balance of the information. Next, you need a method to store the information. (A Database would really be handy for this.) Finally, a script like a Content Management System to retrieve the data from the Database for display.All in all, not exactly a Beginner's script, but a project to allow you to learn php scripting.

Link to comment
Share on other sites

Thanks for that. I completely understand how to get the product code into the form. Thanks so much.Regarding the additional fields on the form... normally the .php file would look like what is below. Say the additional field was "Price". Would I add $price to $message or $headers? Obviously the information itself would need to go into the message body - so I assume I would add it to the $message= statement?<?php$to = "receiver@hisemail.com";$subject = $_POST ['subject'];$message = $_POST ['message'];$email = $_POST ['email'];$headers = 'From: $name, $email';mail($to,$subject,$message,"From:$name <$email>\r\n");echo "<b>Your mail has been sent.<br>We will contact you shortly</b>";?>Regarding attaching the image to the contact form, even though I realise using a database (SQL??) is easier, for the time being I want the image to be sent as an attachment to the actual email I receive. I have spent most of the night trying to find out how to do this and have encountered everything from MIME to PHPMail (which I can't seem to download off the site for some reason). I am so confused around this one... but understand that the function is pretty advanced and I am totally brand new to any form of Server Scripting.

Link to comment
Share on other sites

Regarding the Product Codes (pc), I don't think I understand as clearly as I thought.Does the entire form then need to be coded into a .php document? ie the form would technically be "echoed" and the subject field would contain the _GET command?Or would I code the form as an HTML document and insert a small piece of php script (namely get the pc) in the subject field?

Link to comment
Share on other sites

I thought you wanted the Product code as the Subject of the email?

$subject = $_POST ['product'];

Have you reviewed the php tutorial on the $_GET query string yet? Understanding this is critical to the issue.http://www.w3schools.com/PHP/php_get.aspAnd the attachment of the image to the email will require some special handling. Google "email attachment scripts". It should use a multi-part mime type and a bunch of other stuff to figure out. Sorry that I don't have a sample, but there are lots on the 'net.

Link to comment
Share on other sites

I want to try and simplify it for myself. As I understand it there are three steps here:1. The user sees a product and wants more information. The user then clicks the "more info" button/link.2. A popup opens with text (Please enter your details and we will get back to you), three form fields (name, telephone number, email) and an "okay" and a "cancel" button.3. Upon clicking "okay" (obviously "cancel" will just close the window) the form is emailed to me with all the information as well as the product code as the subject.The first step involves the link <a href="infoform.php?pc=A001> where pc is the product code. If this is correct this means that the next file to be accessed by the server will be infoform.php. Should that be the file that opens in the popup? Or should I rather link to infoform.html (which will open in the popup) and then when the user presses "okay", only then will the php script - infoform.php - run (sending the mail with the info and the product code).If this is right then how do I communicate the value of pc through the process? Won't it get lost during infoform.html?

Link to comment
Share on other sites

say this is your "more info" link

<a href="infoform.php?pc=A001">more info</a>

in your infoform.php,

<form action="email.php" method="post"><label for="pc">Product Code:</label><input type="text" name="pc" readonly="readonly" value="<?php echo $_GET['pc']?>" />

<label for="email">Email:</label><input type="text" name="email" />...etc...<input type="submit" name="action" value="ok" /></form>the form above shows the product code to the user, provides input for email address and an "ok" submit button.when user hits "ok" button, email.php kicks in.here is how to access the product code in your email.php,

$productCode = $_POST['pc'];$email = $_POST['email'];...mail(...);

that should pass product code properly.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...