Solved

Use a CGI to push a Specific Page and include variables --

Posted on 2013-06-28
14
159 Views
Last Modified: 2014-10-14
Good Afternoon,

    I am migrating an application to WordPress.  After the USer logs in they receive a page to do a function and when they submit the form in the page it calls a CGI program written in C.   That program returns a very vanilla page saying that the task was completed and a transaction number or failed and an errno & message.  

     Now we would like to use a Word Press page with the Data inbedded in it so the Look and feel is the same..  

  Current generated HTML looks like this --

 
<html>
<head><br>
<title>Send Results</title>
</head>
<body>
<h1 align="center"><br>
Send Page Results<br></h1><p align="center">
<br>
</p><h2 align="center"> 250 Message 1320894 Sent Successfully
 
</h2><h3 align="center"> Press back to contine.
</h3>
</body>
</html>

Open in new window


Hope someone can suggest changes to the HTML to result in a  Wordpress "page" with some data included.  

TIA --
JMS..
0
Comment
Question by:Phonebuff
  • 7
  • 4
14 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
Hope someone can suggest changes to the HTML to result in a  Wordpress "page" with some data included.  

Because all WordPress "pages" are entries in a database and not individual files you are going to need to change the CGI program in a non-trivial way if you want it to appear in WordPress.  

If the user is logging in to a WordPress site and will be presented with a form that calls the CGI program, I would modify the form to use AJAX and the CGI output to return just the HTML of the the results without the complete page structure (strip the html, head, body tags).  That should get you the results you are looking for.
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
Thanks for the quick response but I am not sure I understand --

In word Press under Pages I created the "Results" page.  with a perm link of

      http://www.wpsite.net/dispaly-page-results

   So if I look at the code coming from my processing CGI I need to do two things I need to tell it to display the page "dispaly-page-results" an I need to send it some free form code to embed in the page.  Are you saying do something like this.

 
<html>
<a href="./dispaly-page-results"
</p><h2 align="center"> 250 Message 1320894 Sent Successfully
</html>
                                  

Open in new window

0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
Comment Utility
No.  You seem to have a fundamental misunderstanding of how WordPress (or any CMS) works.

When you create a new page or post you are merely inserting a row in the wp-posts MySQL table.  The permalink is used to generate a database query that calls the matching row and outputs the content to the appropriate template file.

When you come from a static, file-by-file based site you can do things like redirect the user to a new URL and have that URL built on the fly by outputting complete code from the CGI application.  In this case that won't work because any redirect will be parsed through WordPress and your Results page will be called.  But lacking any other scripting, the results you are looking for won't be there.

So you need to use PHP to capture the output from the CGI script and make it available to WordPress somehow.  In my original post, I suggest you use AJAX to call the CGI script and collect its result which would be simply:

<h2 align="center"> 250 Message 1320894 Sent Successfully</h2>

Open in new window


Because you would be using AJAX, there is no need to do the redirect.  Clicking the button will fire the script and then you output the result.  If you're not familiar with using AJAX to handle form operations, then the preceeding paragraphs are gibberish to you, correct?
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
Correct -- Afraid I am lost --

 I have a page with an HTML snippit in it that uses a standard <form action="/cgi-bin/pagecgi.cgi" method="post" ........................>  To execute the program on submit that outputs the simple HTML in my initial post.

The program in C writes to standard out.  .....
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
The program in C writes to standard out.  ...

So to translate to WordPress you would need to create a Custom Page Template for the results page and add PHP scripting there to read STDOUT and echo it back.
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
That sort of makes sense but I still don't think I understand what my code has to write out to get Wordpress to server the Results page / Custom Template -- The echo part seems easy enough..

Page --  

         CGI Program

                 Page --

Have to go out for an hour or two them I will read the Custom Page Template link you have provided a few more times and see if it sinks in.

THANK You.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
I still don't think I understand what my code has to write out to get Wordpress to server the Results page / Custom Template

The code has to redirect the user to a new URL that calls a custom page template which has the appropriate scripting to read STDOUT and echo it back.  In PHP, we do this with the header() function:

header("Location: http://yoursite.com/results-page/");

Open in new window


Alternately, you may want to write STDOUT to a temporary file and call it back with a query string:

header("Location: http://yoursite.com/results-page/?somevar=somevalue");

Open in new window


And the PHP in the custom template reads somevar and uses a simple include() function to open somevalue.txt and echo contents.  There's a lot of ways to accomplish the goal...
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
FYI -- Just a quick update on this.  Still reading and learning.  No solution for this issue yet --
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
So I have tried replacing my code with this --

sendHTML() {
                printf("Content-type: text/html\n") ;
                printf("\n");
                printf("<html>\n");
                printf("<head><br>\n");
                printf("<title>Send Page Results</title>\n");
                printf("</head>\n");
                printf("<body>\n");
                printf("<?php\n");
                printf("$post_id = 30;\n");
                printf("$queried_post = get_post($post_id);\n");
                printf("?>\n");
                printf("<h2><?php echo $queried_post->post_title; ?></h2>\n");
                printf("<?php echo $queried_post->post_content; ?>\n");
                printf("</body>\n") ;
                printf("</html>\n") ;
}

Open in new window


  All I get is the constant post_title; ?> in H2
  and the constant post_content; ?>

Even though view source appears to be what I wrote from the code --

<html>
<head><br>
<title>Send Page Results</title>
</head>
<body>
<?php
$post_id = 30;
$queried_post = get_post($post_id);
?>
<h2><?php echo $queried_post->post_title; ?></h2>
<?php echo $queried_post->post_content; ?>
</body>
</html>

Open in new window




  ======================
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
 
LVL 15

Author Comment

by:Phonebuff
Comment Utility
Sorry,

     I lost track of this post. The support helped a lot and I need to review it, award points and properly close it --

     Will try and do so in the next couple of days.,
0
 
LVL 15

Author Closing Comment

by:Phonebuff
Comment Utility
Sorry for the late update ---   I was able to make this work from the C application code, but in the long run have now found it more flexible and easier to work with by rewriting the code in PHP and properly handling the building of a Wordpress page --  As well as some SQL functions.

--------------
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now