Build Your Own Business Website header image

A Conversation About How to Integrate a Standalone PHP Application with WordPress

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

In this session we talk about how to integrate a standalone PHP application with WordPress. We begin with some initial steps in terms of setting up a custom template where we apply a small hook function to render some basic content out to one WordPress page on a site and the submit button that validates the registration form. We talk about hooks as a placeholder in WordPress and how that works for HTML for the form or whatever it is that is the initial controlling function. We also talk about inserting a package into a page to make it behave as if the page is a static HTML page.

Lastly, we demonstrate how to configure the use of SSL on WordPress since it’s much easier to make the whole site use https because WordPress relies on assembling assets from different places. If any of those places are not SSL, then you get that error in the browser since the site is not secure.

Video Transcript

Member: My questions picking up from the forum thread that I started yesterday was related to bringing over a static site which has a perl form to which submits to a merchant service.

Rick: Yes, yes.

Member: So, you basically gave some initial steps in terms of setting up a custom template which I followed and applied a small hook function which I got working to just render some basic content out to one wordpress page on my site.

The question I have to fill out that process is that, the form needs to be pre-filled under backend validation errors. I just want to make sure I have this correct. So, when the page renders initially, obviously there’s no errors, there’s no content on the form, the hook in the custom template will render the content. As someone fills in the content and then leaves out a required field or whatever, the submit button then would point at a separate php registration script on the site and actually take fields, do the validation. If there’s an error, obviously it will go pass, if there’s an error, it will just redirect to the merchant service and the merchant service will process the credit card information and then redirect back to the site.

But if there’s an error, I guess I would simply post to the registration page, the form page… So yeah, the wordpress page is called registration, so I would just post back to that page and the hook function would then look for the php post variables or get variables and I would populate, put a variable in there that says error occurred. And if it finds that error occurred, it would look for the rest of the variable and fills out the whole page.

Rick: Yes. So, ordinarily, a form action references a specific URL right?

Member: Correct.

Rick: And what you’re doing is, your form action is referencing a script.

Member: Correct.

Rick: Now, presumably, somewhere in that script, because this is a working script that currently works right now just fine using…

Member: Working in perl…

Rick: Yeah, in perl. So, somewhere in that script, there is a reference back to a URL when there’s an error.

Member: Yeah, the current script doesn’t need a reference, it just renders its output. Because it’s rendering a self-contained site, you know what I mean? There’s no management system around it, it simply takes the form, the text that it said an error and just render the form back out again, with the form pre-filled plus any error indication.

Rick: So, it’s rendering back to its html URL…

Member: Correct.

Rick: And it will work exactly that same way. See what we’re doing here is we are making one specific page on your wordpress site behave like a static html page. The fact that it’s in a content management system doesn’t have anything to do with it.

Member: That’s the point.

Rick: Because we’re taking this nice, neat, little package of static html and we and flopping it into the middle of this WordPress template.

Member: Correct. So, the hook function renders that content.

Rick: Well, no, the hook function, it depends what you mean by a hook function at this point, but, what you’re doing is you are hooking the initial function that holds all of this stuff. You are hooking that to that hook. It probably is just the html to the form but whatever it is that, sort of the initial controlling function, that’s the thing you’re hooking to the hook.

Member: Correct!

Rick: Because in WordPress a hook is just a placeholder. It’s just a place that something happens.

Member: Correct, so in the custom form, you had me pull out the WordPress loop and insert a html container…

Rick: Right

Member: And then define the name of the hook for Thesis, right?

Rick: Right.

Member: So, when the page renders, the Thesis runs and it basically calls the hook function.

Rick: Yes.

Member: And the output of my hook function is the form.

Rick: Right.

Member: And it populates within the page. And at the bottom of that form, is a submit button. So the action on the form would, in my mind, need to submit to a separate php script.

Rick: No.

Member: No?

Rick: No, I would’t be… no, again, you’ve got your little package and you insert that little package into the page and then it behaves as if that page was a static html page.

Member: Oh, okay. So, I’m getting it now. It’s sinking in. So, literally, the form could submit to itself. Like it could submit to registration page…

Rick: Yeah, it’s what it is doing in html.

Member: Right, right. So then in that case, it could read the parameters, figure out that it’s an initial submission, do the validation, render the page again or redirect to the merchant service.

Rick: Right.

Member: And now finally, the merchant service, when it redirects back to my site, I need to pull in parameters from that redirects. That could be a separate thank you page which works much in the same manner.

Rick: Absolutely, yeah. Because again, it’s a get, right? I mean, It’s kind of include those variables in the result that it sends back.

Member: Right, it need to read the get or the post.

Rick: Yeah, and so you’ll just pick them up and just use them as you see fit.

Member: Okay

Rick: Now, what file are you creating this in?

Member: In the Carta Skin Custom php.

Rick: Okay, right. So, just like in any other ordinary php system, if some of this stuff is in included files then you’ll need to those files, right? You’ll need to have an include statement and include those files and if it can all be copied into custom php then that’s great.

Member: Yeah, it will rather be easy to organize it in include files to make the html a little easier to manage, right.

Rick: Yeah, so…

Member: So, I just want to verify those steps. I just thought a separate script is needed outside of that hook function, essentially…

Rick: You shouldn’t have to modify the script that you’re doing that work at all. All you’re really doing is hooking it into place but once it’s hooked into place, the same script that worked on a static html page will be working on the WordPress page.

Member: Okay, so the… and why remove the WP loop box, out of curiosity?

Rick: Because you’re not using the loop.

Member: Just don’t need it, yeah.

Rick: Right. I mean, you could include the loop and could include a post box and you might have some little introductory text up there before, I mean you certainly could do that but this form is outside the loop.

Member: Right.
Rick: And doesn’t interact with the loop at all.

Member: Correct. One final question and that is in terms of SSL for the form. I’ve read somewhere that for WordPress, you want to use SSL on the entire site because on my current site it’s just the registration page. So all the links on my current site when refer to the registration page, they are https references. Nowhere else on the site is https used. So for WordPress, what would… any suggestion?

Rick: Well, for WordPress it’s much easier to make the whole site https because WordPress relies on assembling assets from a bunch of different places. And if any of those places are not SSL like your wp-content folder where you’ve got a CSS file or an image, if any of the assets the page uses are not https then you get that little, you know, error in the browser saying the site is not secure.

Member: Right. So, is there any configuration to make the site SSL, I mean, all the links that I would generate for images and what-not, I would either leave off for protocol and let the site like handle it? Because that’s typically…

Rick: Well, we’re talking about CSS files too, though.

Member: Okay.

Rick: Right, CSS file or javascript file or any other… that’s just why it’s a problem because it’s not just images, although images are often the big culprit but it’s really, every file that is referenced by that page has to be https or the browser sends the error message saying the site is not secure.

Member: Right, so is there a WordPress setting somewhere, configuration somewhere?

Rick: Yeah, you wouldn’t believe how easy it is. It’s over here in Settings, General. And instead of http, you put https in both of those places.

Member: (laughs) Okay

Rick: Now, you’re going to have to go back and make sure that you don’t have any hard-coded links in your site that are http…

Member: Right

Rick: But besides that, that’s all it is.

Member: Excellent.

Rick: Now, don’t hit save until you made https in both places…

Member: Right

Rick: You don’t want your website URL https and then come down here and save changes and have these two things different, then your world are hurt but send them both to https and save changes. And then, if you’re using images and Thesis, like if you’re using a skin editor and Thesis, those are all relative URLS so you don’t have to worry about those. Because since they’re all relative URLs, they don’t have an http in front of them anyway.

Although if you have Custom CSS where you’ve written a URL for an image here, you’d need to change the information from http to https.

Member: Sure.

Rick: But all your javascript files, css files and everything else, everything that WordPress that automatically serves will have been served with the https. And so you just have a little bit of hunting for other stuff.

Member: Okay.

Rick: Okay?

Member: That’s helpful, really helpful. Thank you so much.

Rick: You’re welcome, well you have a great evening.

Member: You too.

Rick: Okay, bye bye.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 comments… add one