Solved

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

Posted on 2013-06-28
14
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
14 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 39285487
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
ID: 39285519
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
ID: 39285538
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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 15

Author Comment

by:Phonebuff
ID: 39285564
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
ID: 39285572
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
ID: 39285583
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 39285661
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
ID: 39294885
FYI -- Just a quick update on this.  Still reading and learning.  No solution for this issue yet --
0
 
LVL 15

Author Comment

by:Phonebuff
ID: 39302790
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
ID: 40378943
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
ID: 40378944
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
ID: 40380707
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

691 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