Forum Moderators: coopster
I'm able to get the CC gateway working, but I also want to to email the pertinent purchase data to him, so he knows there is a sale.
He's on a FreeBSD box so no ASP and no JSP (I *know* those languages) so PhP is my only alternative (or CGI).
There is a built-in mailer function which works with CGI, but it needs to redirect.
Any ideas on how I can do this with one or two pages?
My idea was to have the validate javascript for the CC form populate the fields of a hidden form which will submit the email, then return to the same page with some type of hidden value. The page should read the post information, and if the hidden value is present, submit the CC form using the POST data.
is this possible, and how would I code it?
Thanks
$formBlock = "
<FORM action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<INPUT type=\"text\" name=\"first_name\" value=\"$_POST[first_name]\" size=\"25\">
<INPUT type=\"text\" name=\"last_name\" value=\"$_POST[last_name]\" size=\"25\">
etc...
<INPUT type=\"hidden\" name = \"op\" value = \"ds\">
<INPUT type=\"submit\" name=\"submit\" value=\"Submit This Form\"></TD></TR>
";
Which makes this page the object of the form action.
Then, the logic for what to do
if ($_POST[op]!= "ds")
{
echo "$form_block";//present the form if op!=ds
}
else if ($_POST[op] == "ds")
{
//error checking
//assemble message
//CC procesing
//Send CC info
mail($to, $subject, $msg, $mailheaders);
echo "<p>Thank you,<B> $_POST[first_name]</B>. We will be contacting your soon.</p>";
}
That is fast and sloppy, but may give you an idea of where to go. Add error messages, security checks, etc as needed
WBF
The logic in this code is simple.
The hidden form field "op" is set to "ds" (do something) only if the form has been shown. So
if ($_POST[op]!= "ds")
{
echo "$form_block";//present the form if op!=ds
}
assures the form is shown the first time. This line
<FORM action=\"$_SERVER[PHP_SELF]\" method=\"post\">
brings the form back to this page, but now $_POST[op} == "ds" (do something), which is process the form. And when it is done processing the form and sending an email, it prints a "Thank You" message
The variable $formBlock is your form with all quotes escaped. If your credit card submission is being sent somewhere else you will need to reload all of the data from the form into a new form for submission, since you can't send the same form to two different places (as far as I know).
Now, I use this code to load a MySQL db while sending a message to the site owner (it's from a contact form). Using that approach, you could build a page that loaded a form from the db, emailed the site owner that an order was awaiting processing, and provided a link. The owner could then review the order information (make sure it wasn't from Nigeria, etc.) and hit the submit button to complete the processing.
I didn't go into any detail on checking for required fields, security manipulations, etc. I concatenate the message in the email from the form fields, e.g.:
$msg = "$_POST[firstName] $_POST[lastName]\n";
$msg .= "$_POST[streetAddy]\n";
etc.
So, I offer the bones and the logic. Can you take it from their?
WBF
$_POST[firstName]
becomes
$firstName
etc.
I also tend to run the array through any filtering functions I am going to use before I use extract(), i.e stripslashes(), addslashes(), etc. It is a bit less coding. Be sure to pass the arrays into the functions by reference or you will be scratching your head wondering what you did wrong.
WBF
In order to submit two separate forms I make a "transition" page.
The reg form shows, with the action of the form a transient page, which receives the POST and sends the mail.
That page also "shows" the hidden form and submit that, which processes the CC info and return to a third page.
it works, but now I want to clean it up and make the mail happen after the CC returns authorized. However, the CC data that returns auth or declined, doesn't include the name, address, etc.
How would I keep a handle on those variables? Is there a session object in php?
Once you use a $_POST variable, you can't use it again.
not true but it depends what you did to it.
I think the only way would be a session, otherwise you could save it somewhere with some type of transaction id and then cross reference on return.
Session handling functions [php.net]
Right now the page sends the email before submitting to the CC, so the recipient doesn't know if the order was good or declined. The information coming back from the CC doesn't include user information either, so I can't grab that from the POST.
I tried getting the session idea working, but I wasn't able to store the data correctly. I'm sure I'll get it, then I can pass the missing information via the Session object and print out a nice receipt, and do the emailing after the order was approved.
I don't want to use a DB at this time.