• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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

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
Phonebuff
Asked:
Phonebuff
  • 7
  • 4
1 Solution
 
Jason C. LevineNo oneCommented:
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
 
PhonebuffAuthor Commented:
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
 
Jason C. LevineNo oneCommented:
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
PhonebuffAuthor Commented:
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
 
Jason C. LevineNo oneCommented:
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
 
PhonebuffAuthor Commented:
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
 
Jason C. LevineNo oneCommented:
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
 
PhonebuffAuthor Commented:
FYI -- Just a quick update on this.  Still reading and learning.  No solution for this issue yet --
0
 
PhonebuffAuthor Commented:
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
 
GaryCommented:
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
 
PhonebuffAuthor Commented:
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
 
PhonebuffAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now