From Form to XML

UGH!! I don’t know where to begin?! :frowning: :frowning:

I am trying to build an interface between my website and the payment gateway “Internet Secure”. They send and receive data using XML - which I have never used.

They gave me some sample ASP code, but that doesn’t help much with PHP?!

I have lots of questions, but I guess the first is…

What should I do with the data I collect in my Payment Form?

Should I first stick it into an array?

Or do I jump right into building an XML string?

Thanks,

Debbie

Maybe you should hire someone to at least write the initial code to get you started and to teach about parsing XML. Or you should just take time to learn about xml format in general and how to parse it with DOMDocument and Xpath.

Last thing you want to do is to “Just stick it into an array” as you put it. This is bad. Take XML topic seriously, not by trial and failure method, especially since it has to do with commerce.

Not much point putting it into an array really if you’re going to start the XML in the same script. I’d be hitting phpclasses.org looking for a xml class that you could use.

XML is very similar to html except you have ‘nodes’ for each bit of data and its name etc. It still transfers over a connection as text but its text that can be parsed by a XML reader (which is something you want to look for in any class you use).

Well, if I store the form data in an array, then I have each piece assigned to a variable which I would think is easier to work with later…

As far as PHPClasses, I don’t want to use object-oriented code, so that wouldn’t help.

XML is very similar to html except you have ‘nodes’ for each bit of data and its name etc. It still transfers over a connection as text but its text that can be parsed by a XML reader (which is something you want to look for in any class you use).

Can’t I build my own?

Debbie

You’re going to be hard pushed to built something simple that reads (properly) XML without using an Object Debbie. :slight_smile:

Thankfully, PHP has SimpleXML which makes things quite intuitive.


<root>
  <users>
    <user name="anthony" id="1" />
    <user name="debbie" id="2" />
  </users>
</root>


<?php
$xml = new SimpleXMLElement($xmlString);

echo $xml->users[0]->user['name']; #anthony
echo $xml->users[1]->user['name']; #debbie

foreach($xml->users as $user){
  printf('(%d) %s', $user['id'], $user['name']);
}

/*
  (1) anthony
  (2) debbie
*/

Well, using something pre-built that was written in OOP is one thing. (Having to know how to code using OOP is another.)

Thankfully, PHP has SimpleXML which makes things quite intuitive.

So what would help this conversation along?

I could post the ASP code they gave me, but am thinking it might help more to just talk things through step by step.

Debbie

Step by Step sounds good.

Okay, are you guys ready for me?! :slight_smile:

So I created a modest “Payment Form”…


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Payment Form</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link type="text/css" rel="stylesheet" href=".css">
		<style type="text/css" >
			form{
				width: 400px;
				margin: 0 auto;
			}

			fieldset{
				margin: 1.5em 0 0 0;
				padding: 0;
			}

			legend{
				margin: 0 0 0 1em;
				color: #000000;
				font-weight: bold;
			}

			fieldset ol{
				padding: 1em 1em 0 1em;
				list-style: none;
			}

			fieldset li{
				padding: 0 0 1em 0;
			}

			fieldset.submit{
				border-style: none;
				padding: 0 0 0 12em;
			}

			label{
				float: left;
				text-align: right;
				width: 10em;
				margin: 0 1em 0 0;
			}

		</style>
	</head>
	<body>
		<form action="process_payment.php">
			<fieldset>
				<legend>Billing Details</legend>
				<ol>
					<li>
						<label for="firstName">First Name:</label>
						<input id="firstName" name="firstName" class="text" type="text" />
					</li>
					<li>
						<label for="middleInitial">M.I.:</label>
						<input id="middleInitial" name="middleInitial" class="text" type="text" />
					</li>
					<li>
						<label for="lastName">Last Name:</label>
						<input id="lastName" name="lastName" class="text" type="text" />
					</li>
					<li>
						<label for="address1">Address1:</label>
						<input id="address1" name="address1" class="text" type="text" />
					</li>
					<li>
						<label for="address2">Address2:</label>
						<input id="address2" name="address2" class="text" type="text" />
					</li>
					<li>
						<label for="city">City:</label>
						<input id="city" name="city" class="text" type="text" />
					</li>
					<li>
						<label for="state">State:</label>
						<input id="state" name="state" class="text" type="text" />
					</li>
					<li>
						<label for="zip">Zip:</label>
						<input id="zip" name="zip" class="text" type="text" />
					</li>
					<li>
						<label for="teleNo">Telephone No.:</label>
						<input id="teleNo" name="teleNo" class="text" type="text" />
					</li>
					<li>
						<label for="email">Email:</label>
						<input id="email" name="email" class="text" type="text" />
					</li>
				</ol>
			</fieldset>

			<fieldset>
				<legend>Credit Card Details</legend>
				<ol>
					<li>
						<label for="cardNumber">Credit Card Number:</label>
						<input id="cardNumber" name="cardNumber" class="text" type="text" />
					</li>
					<li>
					<select name="expMonth">
						<option></option>
						<option>01</option>
						<option>02</option>
						<option>03</option>
						<option>04</option>
						<option>05</option>
						<option>06</option>
						<option>07</option>
						<option>08</option>
						<option>09</option>
						<option>10</option>
						<option>11</option>
						<option>12</option>
					</select>
					<select name="expYear">
						<option></option>
						<option>2011</option>
						<option>2012</option>
						<option>2013</option>
						<option>2014</option>
						<option>2015</option>
						<option>2016</option>
						<option>2017</option>
						<option>2018</option>
						<option>2019</option>
						<option>2020</option>
					</select>
					<li>
						<label for="cvv">CVV Code:</label>
						<input id="cvv" name="cvv" class="text" type="text" />
					</li>
				</ol>
			</fieldset>

			<fieldset class="submit">
				<input class="submit" type="submit" value="Process Order" />
			</fieldset>
		</form>
	</body>
</html>

Before going onward, let me say that I am pining over going with Internet Secure or Authorize.net. Each has advantages and disadvantages, but the thing that is annoying me with Internet Secure is there way looks harder and there is less support.

At the same time, this would be a great chance to be “baptized by fire” and get the basics of XML and E-commerce down!! :smiley:

So once I have a customer’s payment info, I need to send it to the Payment Gateway.

Regardless of the format the Payment Gateway uses, I would think - like I mentioned above before the sarcasm started - that it might be a good idea to store each form value in a variable (e.g. array)?! :-/

Agree or not?

I guess I need to add some PHP to do that…

Debbie

By the way, phpclasses.org in one of the worst source for php classes. If you just avoid it you are going to be doing yourself a great favor. In short - any script kid can submit class to phpclasses.org, there is no quality assurance there, no test cases for most classes, no coding standard. There could be some good classes there but more than half are terrible, especially for beginners that just trust classes they download. If you want to use existing classes, use reputable sources like PEAR or Zend framework. They have good XML classes, but you probably will do well without any extra classes, just use SimpleXML or DOMDocument - both of them can use XPath, you just have to take time and learn about XML and Xpath

As it looks like you’re attempting to collect Credit Card details, I suggest you have a very good read of this thread.

And one-liners certainly won’t get me there…

Debbie

Hence the link to the thread, where I contribute to the matter in hand. You would ask I repeat myself, in replacement of you reading the provided thread?

You know what you’re doing, Anthony… Stop Trolling.

If you don’t like me or my threads and you don’t want to help then fine.

But your one-liners of “Oh, I think you know the answer” and “go read the manual” are getting really old.

I don’t appreciate being treated as lazy or dumb. And that is exactly how you make me feel.

(I spent the entire day yesterday Googling what should have come up the first time, and yet I can’t find anything out there to help me. Which means I either am looking in the wrong places or don’t know the right question(s) to ask.)

There are sooo many people that are helpful on SitePoint (and online) so it always blows me away when people make posts like you.

I am at SitePoint because I don’t know the answers and I need help. And sending me off to the library to go figure it out on my own clearly won’t help. Someone who has time and enjoys discussing computers and programming and likes mentoring people so that they can be more independent down the road is what will help.

Guess it is a difference in people and personalities between SitePoint forums!

But I digress… :rolleyes:

Debbie

Hi Debbie.

Why would you not start at the manual for the language you’re using, would you buy a new TV and Google for how to turn it on instead of reading the manual?

I’m actually quite admirable of the task you’re undertaking, but sadly, I think you lack a fundamental understanding of the technologies you seek to employ. This is OK though, as long as you’re willing learn the fundamentals as you go. As lampcms.com pointed out, if you’re going to be using XML, you need to have at least a very basic understanding if it.

Refusing to read the sections of the manual pointed out for you, and expecting members to ‘talk you through it’ is quite remiss of your role in this endeavour.

You’re right, SitePoint does have some outstanding members, it’s a community to be proud of. Unfortunately, it also has members who are simply here to take all they can get with little or no effort from themselves and unwilling to take the advice offered and persevere.

Many of your threads have been very active, filled with helpful posts from various members.

I’m comfortable with the level of service I have provided to you.

Good luck, I hope you get there.

Anthony.

Hold on guys, lets cool it and start again eh?

Debbie, meet Anthony. Anthony, meet Debbie.

Debbie, Anthony is one of sitepoints finest and frankly his advice is worth listening to but like all pro coders he doesn’t like wasting time. The pro’s are always busy and will give you links to read and hints tips but they expect you as a learner to do the leg work and research etc. Unfortunately the pro’s can unintentionally come across as arrogant and unhelpful when in fact they’re actually being the opposite but are just too busy to actually express themselves properly.

Trust me, if Anthony is in this thread its a good thing. I can promise you that. If you think he’s being unreasonable then you would hate some of the TeamB people who assist on the Borland/Codegear/Embacadero groups for Delphi. Some of them can write text which literally makes you feel like they’re cutting you up when they disect your code and tell you whats wrong. They don’t do it in a softly softly way they just use comments like “Thats wrong, this won’t work, you’ve not listened to me, stop wasting my time” etc and thats the polite stuff. They can get a LOT snottier and can really insult you without trying. It takes some people years to get used to the way they think but its worth it because when you get used to it and start learning from the Pro’s they see you making the effort and when they start saying “Yes, thats right, almost, good code, exactly” etc it makes you feel a lot better about yourself and like you’re actually becoming a lot better. You then realise that you gained their respect too and that is always a good thing.

Honestly, I’ve had some REAL arguments with some of the best programmers out there and I can promise you Anthony isn’t being difficult though it might seem like that until you realise thats just how pro coders are. They don’t tend to worry about making friends they just communicate the point - even if they’re literally pointing you to another topic. It’s pretty common and its just one of those things - nothing personal :wink:

You assume I know nothing about PHP or programming or computers. That is wrong.

My problem is that I have read TONS of books on all-things-web, but unfortunately with the Global Economic (and Geographic and Geologic) Meltdown, my IT goals have been put on hold again and again.

So instead of starting over from scratch, it makes sense to find people who can help get me back up to speed.

I have most of the knowledge I need to get done what I want, I just need a patient and kind soul to “jump start” my brain.

(They don’t make people in their 40s go back to grammar school that are coming back to college to get their Masters Degree.)

Yes, I could go back and spend 6-months reading books and manuals again, but that seems pointless when I have already found people willing to help me “connect the dots” and get back up to speed.

I’m actually quite admirable of the task you’re undertaking,

The task isn’t that hard. Finding the right people in 2011 is much harder than in 1990s.

but sadly, I think you lack a fundamental understanding of the technologies you seek to employ.

When I wrote my first program in college there wasn’t Windows…

This is OK though, as long as you’re willing learn the fundamentals as you go. As lampcms.com pointed out, if you’re going to be using XML, you need to have at least a very basic understanding if it.

I do understand the basics.

That doesn’t mean I know how to use SimpleXML or feel comfortable using the object-oriented approach some solutions require.

It also doesn’t mean I know how to eloquently take data from an HTML Form and slap it into an XML schema easily.

I could do…


<?php
$myXMLstring = '<xxxFirstName>' . $firstName . '</xxxFirstName>' . and so on
?>

but that seems pretty lame?!

Refusing to read the sections of the manual pointed out for you, and expecting members to ‘talk you through it’ is quite remiss of your role in this endeavour.

I was up until 2:00a.m. Googling and reading and trying to learn what I could.

Again, you assume I make no effort.

If manuals were so well-written, SitePoint would disappear! (What makes SitePoint work is the collaborative nature of people helping people…)

You’re right, SitePoint does have some outstanding members, it’s a community to be proud of. Unfortunately, it also has members who are simply here to take all they can get with little or no effort from themselves and unwilling to take the advice offered and persevere.

If you think I am one of those bad people, then why are you talking to me?

Many of your threads have been very active, filled with helpful posts from various members.

Right, and just because I don’t have all of the solutions doesn’t mean I don’t contribute to the group’s IQ.

My threads are often large and popular because I ask interesting questions and I challenge people’s thinking, and we all gain from that.

And I’d like to think I have made friends on SitePoint, which is why this conversation is embarrassing since you question my character, my agenda, and my effort.

I’m comfortable with the level of service I have provided to you.

Good luck, I hope you get there.

Anthony.

Since you have so many issues with me, maybe you should not respond to my threads…

Debbie

Then he should keep off forums.

When teaching becomes a drudgery, ten it’s time to find a new calling.

The pro’s are always busy and will give you links to read and hints tips but they expect you as a learner to do the leg work and research etc.

Answering a question directly takes the same if not less time than sending people on a wild goose chase.

Unfortunately the pro’s can unintentionally come across as arrogant and unhelpful when in fact they’re actually being the opposite but are just too busy to actually express themselves properly.

Quality over quantity.

I tend to ask pretty good and specific questions. And I know that I can easily clarify things. So helping me in the smallest amount of available time isn’t hard. (Versus the all too common… “How do I build a website?”)

Trust me, if Anthony is in this thread its a good thing.

Honestly, I can’t recall one post he has made so far this year that I recall or found helpful.

“Drive-by” posts never help.

And yet I can think of dozens of people that I have had cordial chats with via Threads and/or PM’s and we have both learned a lot from the conversations.

I can promise you that. If you think he’s being unreasonable then you would hate some of the TeamB people who assist on the Borland/Codegear/Embacadero groups for Delphi. Some of them can write text which literally makes you feel like they’re cutting you up when they disect your code and tell you whats wrong.

There is no shortage of people who do things the wrong way. And the civilty went out the window on the Internet in the late 1990’s.

They don’t do it in a softly softly way they just use comments like “Thats wrong, this won’t work, you’ve not listened to me, stop wasting my time” etc and thats the polite stuff.

I don’t mind that if people are attempting to answer my questions.

Nothing is more annoying online than asking “How do I clean a wool sweater?” and getting directions to Big Ben?!

They can get a LOT snottier and can really insult you without trying.

I never called Anthony “snotty”.

I just think he likes to type random comments that often don’t come close to what I am asking, and they are often in a very passive-aggressive nature (e.g. “I think you know the answer…” and “Maybe you should go look it up…”)

That is by definition what a Troll does.

(If you can’t say something nice or useful then why bother?)

It takes some people years to get used to the way they think but its worth it

If I had years to get answers to basic questions I wouldn’t come here. I would go back to college and spend the next decade just reading quietly in the library.

People tend to ask others for help because they have exhausted their own resources and need help in the here and now.

because when you get used to it and start learning from the Pro’s they see you making the effort and when they start saying “Yes, thats right, almost, good code, exactly” etc it makes you feel a lot better about yourself and like you’re actually becoming a lot better. You then realise that you gained their respect too and that is always a good thing.

I usually break my questions down into smaller parts so I can quickly learn.

My goal is to learn, and learn quickly.

I always set myself up to succeed.

That is why it is so perplexing that some people take simple requests for help and make them gigantic.

Honestly, I’ve had some REAL arguments with some of the best programmers out there and I can promise you Anthony isn’t being difficult though it might seem like that until you realise thats just how pro coders are.

We never get to debates.

I have never even had a conversation with Anthony.

That is the problem.

Drive-by one-liner about how I can figure it out on my own and then see-ya.

(The guy must have a lot of time on his hands?!)

They don’t tend to worry about making friends they just communicate the point - even if they’re literally pointing you to another topic. It’s pretty common and its just one of those things - nothing personal :wink:

That’s there loss.

The people who I have learned the most from on SitePoint and elsewhere are the ones who I stay in touch with.

They take time to get to know me, my goals, and when they lace into my code, at least they stick around to help me get better at it.

It’s called a “relationship” and “continuity”…

The “pro-coder” approach you describe is like visiting your kid once a month for an hour and thinking that it helps. End result? Dysfunctional kid.

Others on SitePoint take the role of teacher/mentor. End result? A kid that can survive on his/her own and is better off.

How people live their lives is up to them.

But if you are going to help someone, then actually try and help…

Okay, I just wasted an hour of my life responding to your post.

Back to work!

Debbie

Hi Debbie

Having read your reply to mine you put across a very convincing argument and if I’m honest I’m actually in agreement with a lot of it. Not much more I can say really other than I was trying to calm things down and might of inadvertently made it worse instead :frowning: :eek:

I’ve seen Anthony post good stuff in the past although I do see what you’re saying so I think I’ll just stick to the helping-where-i-can thing instead and leave you two to sort it out :wink:

There can never be too many “peace-makers” in the world, so no worries! :lol:

I’ve seen Anthony post good stuff in the past although I do see what you’re saying so I think I’ll just stick to the helping-where-i-can thing instead and leave you two to sort it out :wink:

I have a simple philosophy in life… (related to this topic)

If you’re gonna “help”, then REALLY “help”!!

To do anything less is just a waste of everyone’s time.

If you were visiting Arizona, and ran into me on a street corner in Phoenix, and asked me how to get to Monument Valley, I wouldn’t just give you directions to Flagstaff only?! And I wouldn’t send you to Tucson either. (And I sure as heck wouldn’t tell you to go buy a map!!!)

But not everyone sees it like that.

Whatever.

I’ll get to where I’m going sooner or later. Just depends on how bumpy the ride is, and whether or not people along the way want to help make it easier on me.

Thanks,

Debbie

Not to be rude but he posted a link to a thread where someone was in your same position, they get php, but have not used xml or ecommerce, in that thread he and others went through the process of explaining it step by step. ( i read the whole thread out of interest ) so no it was not a link to a manual or some short little nic of info instead he posted a link to what you are asking him to post here… maybe he should’ve just copy paste that whole thread into here?? I think not he posted you a valuable resource with exactly the information you are asking for (oh by the way its a thread here at sitepoint)

If you were visiting Arizona, and ran into me on a street corner in Phoenix, and asked me how to get to Monument Valley, I wouldn’t just give you directions to Flagstaff only?! And I wouldn’t send you to Tucson either. (And I sure as heck wouldn’t tell you to go buy a map!!!)

But if you had a piece of paper in your pocket with the directions on it you would prolly hand it to him, instead of reading them aloud while he writes them down.

/endrant