Getting Data from a Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Getting Data from a Form

Post by Tomcat7194 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello. I am trying to get data in a PHP readable format from http://noosphere.princeton.edu/data/basket_csv.html

Here is a snippet of the source code for that form:


[syntax="html"]<form method=get name="request" action="/cgi-bin/eggdatareq.pl">
<input type=hidden name=z value="1">
<center>

<table border cellpadding=5>

<tr>
<th>
    Date:
<td>

    <input type="text" name="year" value="1998" size="5">
    <select name=month size=1>
        <option value=1> January
        <option value=2>February
        <option value=3>March
        <option value=4>April
        <option value=5>May
        <option value=6>June
        <option value=7>July
        <option value=8>August
        <option value=9>September
        <option value=10>October
        <option value=11>November
        <option value=12>December
    </select>
    <input type="text" name="day" value="1" size="3">
Basically, I want to have PHP send a request to http://noosphere.princeton.edu/cgi-bin/eggdatareq.pl with "year" set to the current year, "date" sent to the current date, etc, just as if a user submitted the form. Doing so should return a CSV file, which I can then process with getcsv().

How can I use PHP to submit a request with the necessary variables to get a .csv file back?

Thanks
Tom[/syntax]


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Why is it being submitted to a Perl script?
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Post by Tomcat7194 »

I guess that's what the site uses to process the form. Will that interfere with my ability to load data into php?
Tom
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Would be best to write both functions in either perl or php, not both.
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Post by Tomcat7194 »

Hmm, well is there a way that I could use Perl to access and process the data, then save it into a MySQL that I could then access with PHP? I want to use the data from this as part of a php script that is already written, so I need to be able to somehow integrate it with PHP.

Also, I've never worked with Perl. Is there a simple way to get and a process a csv file from that form? If not, can you refer me to tutorial where I can learn how to do that sort of thing.

Thanks for your help
Tom
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I don't know perl very well either -- you would have to go into the perl script and either have it redirect to the PHP script or print a link to the PHP script.
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Post by Tomcat7194 »

Here's a thought--could I make a PHP page that would use headers to submit a form to the perl file with the necessary variables, and then somehow grab the csv file that the perl file generates?

Cause when you fill out the form @ http://noosphere.princeton.edu/data/extract.html, it just takes you to an HTML page with all the data on it. So if I made my own form that sent the variables, could I somehow use PHP to grab the resultant HTML file?

Tom
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

You could submit to the PHP script, and use include("http://noosphere.princeton.edu/cgi-bin/eggdatareq.pl") in the PHP script to execute the perl script. You must use the URL in the include call, not the path name.

edit: you would also have to pass the form data from the php script to the perl script somehow. might be better to have the perl script redirect to the php script after it's done.
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Post by Tomcat7194 »

The problem though is that I can't edit the Perl script--the GCP told me I could use their data, but they didn't give me access to their server. Maybe I could make my own Perl script on my server that would send data to their script, get the resultant csv file, and then stick the data into MySQL...
Tom
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Is the perl script returning a csv file? Are you able to pass information to that script (like the date)? If so, how does the perl script accept that information.

If you are only trying to get the output of that perl script, try http://www.php.net/file_get_contents
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Alright, now that I understand your original question (I'm apparently slow), just copy that form from the site onto your page. Have the form submit to your php script. In that script, construct the url that you want to pass to the perl script (e.g., http://noosphere.princeton.edu/cgi-bin/ ... year=$_GET['year']&month=$_GET['month']......). Use file_get_contents with the constructed url as the argument, and you should have the output of the perl script in a string.
Post Reply