Forum Moderators: coopster

Message Too Old, No Replies

Save form data to file *AND* do something else with it?

Trying to figure out how to do two actions on a form.

         

Phorce1

2:44 am on Jun 8, 2003 (gmt 0)

10+ Year Member



OK -- Yesterday our credit card processor posted a notice that on the 16th of June we will no longer be able to retrieve cardholder data using a batch download from their secure server. 10 days notice -- wonderful.

This was dropped in my lap because I'm the most persistent when presented with a challenge. ;) I've been web surfing trying to find the answers to my questions for the last 14 hours or so -- I have a headache now.

Our customers have been entering initial order information without CC number in a form on our non-secure server. That data is forwarded via POST to the credit card processor's secure server where the customers enter the CC number and expiration date. Later we wre using a batch download from the secure server to retrieve the full billing information in a CSV file to import to our billing software for monthly re-billing.

As of the 16th we need to move our form to our secure server (for which we still need to purchase and install a certificate on Monday), have our form collect the CC number as well as the rest of the information, write the form data to a local CSV file in the format expected by our billing software, *AND* send the data via the POST method over a secure connection to the proccessor's secure server.

Most of us in the office can handle HTML pretty well. Writing a CGI script from scratch is beyond us.

  • Is there a free script out there that I can grab quickly and start working with?

  • Can I do TWO actions from an HTML form? I need to use an action to write the variables to a local file in CSV format then a second action to POST the data to an https server script page.

Thank you for any help available, we are currently in "panic mode". :(

Gerald

willybfriendly

3:28 am on Jun 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using PHP/MySQL this would be pretty easy.

<form action="page/on/my/site.php" method="post">

yada yada yada

</form>

Then on your php page save the customer data to the db, load the $_POST data back into hidden form fields and send it on.

If you are putting in 14 hour days, ten days is plenty of time to be up and running ;)

WBF

Phorce1

4:23 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Probably time to read up on php some more. I was thinking I would end up having to find a script that would do the file writing. I've never used php to write out to a text file.

Not using MySQL. The billing program is a standalone app that was designed to work with the data files downloaded from Authorize.Net. I just need to write the data out to a CSV file in the same format that they were sending. We have example files to work with from previous downloads.

I have the php docs stored here locally plus a couple of good searchable tutorials. I should be able to cobble something together. I'll load the test forms on the apache-ssl server I have running at the house for remote testing.

I work 59.5 hours/week (usually). 1530 - 0000 Thursday then 0700 - 0000 Friday/Saturday/Sunday (yes, 17 hour days). And, since I live an hour away I usually just stay here at the office (all the amenities except a shower <sigh>) for the full 80 hours.

Gerald

jaski

5:30 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Can I do TWO actions from an HTML form?

Not really. The way some thing like this is *normally* done is .. the form submits data to your secure server .. and your secure server in turn connects to the processor's server and posts data and gets response from there and shows it to the user.

However I do not see any thing technically wrong with a 2 step method willybfriendly has suggested. Should be easier if programming is the challenge.

jatar_k

5:47 am on Jun 8, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Phorce1,

How about the quick and dirty script example for writing to a file.

writing to a file is pretty simple. open it, write it, close it.

something like this would work.

$writetocsv = $_POST['field1'] . "," . $_POST['field2'] . "," . $_POST['field3'];

The $_POST [php.net] array holds all the data posted to the script. You access them as above with the element name from the form replacing field1/2/3. You concatenate them together in the order you want putting a comma in between.

$fp = fopen [php.net]("/dir/file.csv","a");

This will open the file for append. You need to change the /dir/file.csv to the path to the file you want to write to.

fwrite [php.net]($fp,$writetocsv);

This writes the content of the variable $writetocsv to the file.

fclose [php.net]($fp);

closes the file handle.

pretty straight forward.

Phorce1

6:07 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Not really. The way some thing like this is *normally* done is .. the form submits data to your secure server .. and your secure server in turn connects to the processor's server and posts data and gets response from there and shows it to the user.

The thing is, what we have NOW works. And Authorize.Net has told us it will continue to work so long as we set up a secure connection to POST from. So, I'm trying to keep what we have that I KNOW is working and add the write to file function. The only change I want to make to our basic form is for it to collect the CC # and expiry date as well as the rest of the billing information that it already collects. Authorize.Net has POST variables defined for the fields, we just haven't been using them because we've been collecting the basic info on our non-secure server to avoid the extra hassle of setting up the secure server.

I've looked through the Authorize.Net interface documentation. I just located some example scripts that they have. I'll be looking through those after I wake up (work "ended" an hour ago and "starts" again 6 hours from now).

Gerald

Phorce1

6:19 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld Phorce1

Thank you for the welcome. I'm glad I found you. I think I'll be spending some time here, helping where I may be able to. Lots of reading to catch up on.

How about the quick and dirty script example for writing to a file.

writing to a file is pretty simple. open it, write it, close it.

I'll be checking your examples as I get back into the php swing. I haven't been doing the web work here at the company I work for, I'm a customer support and hardware/linux tech. My personal site is just a small bit of html as a front for what is mostly photo albums generated on my linux box by "album" from Dave's Marginal Hacks. I did a whole lot of bash/sed scripting around my use of 'album' to alter the generated html but none of it is server side.

Thanks again,

Gerald

[edited by: jatar_k at 3:25 pm (utc) on June 8, 2003]
[edit reason] no urls thanks [/edit]

Phorce1

6:22 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld Phorce1

So far, the only thing I've found slightly annoying is the use of BCC: to send notices of replies. I'm going to have to adjust my .procmailrc to catch them before they drop out to my "catchall" folder. <grin>

G

jaski

7:39 am on Jun 8, 2003 (gmt 0)

10+ Year Member



Also note that in the two step method .. (in which you first write to your file .. then send form back to user with hidden fields for submission to processor AUTHORIZE.NET) .. you will be writing to file every time some one submits it.. ie not "successful transactions only" .. as probably you might have been getting earlier ..

jenlleone

7:04 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Hi guys, I'm new to the forum and new to php. Glad to be here!

Jatar_K, THANK YOU for the quick and dirty $writetocsv example you gave, it worked like a charm! Unfortunately, only for the first record... and then each subsequent record was appended to the first/prior record in the last column in the csv file. For instance:

EmailAddr_ / FirstName_ / LastName_ /
Email 1 / First 1 / Last 1 /
/ Last 1+Email 2 / First 2 / Last 2 /

and so on...

But, I need the data from each form submission to begin in a new row so it will look like this:

EmailAddr_ / FirstName_ / LastName_ /
Email 1 / First 1 / Last 1 /
Email 2 / First 2 / Last 2 /
Email 3 / First 3 / Last 3 /

...etc.

How can I get this done? I appreciate any additional help you can give.

jenlleone

9:11 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Never mind my last post... I found the error and it was easily fixed. :)

Demaestro

9:36 pm on Feb 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can also do it using an Ajax implementation.

<form id="order_form" submit="form_sub.php" onsubmit="Ajax.submitForm('order_form', '',{method:'post', url:'/form_sub_2.php', async:false});">

</form>

You will find many Ajax.submitForm functions prebuilt... YUI and Spry both have one.

I am using this method in a few places and find it more elegant then having the first submit page do the work of two.

[edited by: Demaestro at 9:38 pm (utc) on Feb. 14, 2008]