views:

40

answers:

1

While I do understand php, I'm more of a sysadmin than a programmer. Add that I really hate HTML and never used AJAX nor javascript :)

I'll have to do a php page that gets data from an HTML form and sends it as an Excel attachment via email. Of course I'd like to reuse as much code as possible from already-made solutions. It's kind of "submit quantities and prices of items" stuff.

Requirements are rather simple:

  • form has a fixed number of columns, most of them are free text and two of them will only accept numerical values (quantity, integer, and price, decimal)
  • it must only accept numerical values in the last two columns, and compute an additional column with the product of them (q.ty * price) either in "realtime" (AJAXy style) or as a final preview step before actually submitting data (compile > hit 'preview' > confirm)
  • form starts with one or some empty rows, if the user fills all of them she must get more free rows (again, AJAXy or clicking are both ok)
  • form will present a final preview of the compiled data, also computing the sum of all quantities and the sum of all prices, and ask for a few more fields (name, email, etc.)
  • build an Excel spreadsheet with the very same structure: rows with items, q.ty, price, a row with totals, and some sparse cells with the additional data (name, mail, etc)
  • send an email to a predefined address with the above excel

How to best implement it?

  • a quick google search reveals many php sources to create an excel spreadsheet, are there any "de facto standard" or any one that stands above the others?
  • is there some pre-made html/ajax/php package to manage the form part and validate data and compute products and sums that I could use instead of writing my own html4 static ugly table? :)

Should it be needed for any of the above components, there's a mysql available.

Thanks

+1  A: 

In answer to the first question, I'd recommend PHPExcel, although I do have a certain vested interest in the library.

The calculations can be handled by writing formula (e.g. =A3*B3 or =SUM(C2:C10) in your worksheets

You can create an Excel workbook from scratch for each request; or you could read in a pre-formatted template, populate it with your data; and then save it and attach the file to your email

Mark Baker
I settled on PHPExcel which seems a really good implementation and also the de-facto standard solution for this kind of things.For the record, I'm coupling it with the LGPL PHPMailer class to handle the mailing part ( http://phpmailer.worxware.com/ )
Luke404