Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

HTML/PHP Web Form

HTML

  • Please log in to reply
2 replies to this topic

#1 chezzy62

chezzy62

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 18 February 2011 - 04:13 PM

Hello everyone!

I had a question about an HTML form on a website. I am helping someone modify a website, and move it to a new server, and I ran into a little speed-bump.

https://www.heavenly...J03&stateAbb=NJ

On this page, there is a very long web form, with a lot of options. I want to copy the exact form. But I don't really know where to go from there. I would like to have it so that when a user submits their order, and presses continue, their order information is sent to my email address.

This is what the email looks like when it is sent:

ON-LINE ORDER
For Heavenly Ham - Lawrenceville, NJ (NJ03)

ORDERED BY:
Name
Address
City, State Zip
Phone Number

EMAIL ADDRESS: abc@123.com
ORDER NUMBER: 198632
ORDER DATE: 12/22/2010 3:38:45 PM

PICK-UP / DELIVERY: Pick-up
PICK-UP DATE / TIME: 12/23/2010 3:30 PM

PRODUCT: Half Ham(7-9 lbs)
QUANTITY: 3
UNIT PRICE: $47.99-$61.99


PRODUCT: Boneless Smoked Turkey(3-4 lbs)
QUANTITY: 1
UNIT PRICE: $28.99-$39.99


NUMBER OF PRODUCTS: 4


How would I go about implementing this function? As far as I've read, I believe a form method = post would work well. However, I don't know where to go from there. Maybe I could make a custom php file?

Any help would be greatly appreciated. :)

Thank you!
Josh.
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 19 February 2011 - 12:40 AM

So you are writing the PHP portion from scratch?

When a form submits data, it sends a POST request to the PHP script which accepts it through the $_POST variable, if for example you have an input form named "lastname" it would be accessible through $_POST['lastname'].

You can actually set the form's action to a test script, such as this:
<html>
<body>
<pre>
<?php print_r($_POST); ?>
</pre>
</body>
</html>
That will print out all of what PHP knows from the form's data, so you can get a better idea of the structure of the elements (such as select box, radio buttons etc.), it could help to also test minor forms of your own, to see what PHP will produce out of them in the $_POST array.

Once you move from there, the mail() function in PHP can send the contents of the email you create out of the POST data, there are many tutorials online, including some on the PHP manual for mail()
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 grisha

grisha

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts
  • Location:Poland
  • Programming Language:C, C++, C#, PHP, JavaScript

Posted 19 February 2011 - 12:46 AM

If the form isn't generated by a script just Ctrl+C, Ctrl+V the HTML code.
Set the action attribute of the form to the new location.
In your PHP script fetch everything that's in the $_POST table. Filter it to avoid XSS.
Get the shipment data from fields like $_POST['RtxtLastName'] and remove those fields from the $_POST table. Put it to a string.
Run foreach on the $_POST table use some regular expressions, move the data from the fields to the output string.
Use mail() to send the string.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download