Jump to content

simple htmp post-get (noob question)


jasonhoblin

Recommended Posts

i'll looking for a snippet of code in php to post a set of variables to a url and then display the return data. example:

 

&field1=a&field2=b&field3=3

https://www.example.com/dir/

 

i searched for a few hours and cannot put the code together. most of the php sites talk about post and get functions, but i cannot find a good, rather working, example. do i need two php pages, one to call the other? do i use html form submit? what tells the page to just display/print the response. i'm sure i can figure out how to parse the info but i'm stuck on first step, post-get data. thanks in advance!

Link to comment
Share on other sites

how are you getting your input?  What does the ending url do for you?

 

Can you show us anything you have written so far?  How about your form that grabs your input values for field1= field2= & field3=  ?

 

Have you ever programmed?

 

i am going to create forms on the page to gather vars and then build and post the url. i think... the server i am posting to will process the vars and return a big string of data. i confident i can parse the data.  i'm sure this is much simpler than it seems. 

 

i haven't done alot of direct coding. i'm a website developer, not a programmer.  i usually hack it by copying and tweaking existing code in any language, but for this instance (pun) i cannot find a working example. 

 

let me know if you can help or point me in the right direction. 

Link to comment
Share on other sites

Sounds like you need to develop your html page with the input form.  The action of that form will call your php script which will grab the input fields from the form and do something with them.  At the end that same script will send some html back with the results of your inputs.  Yes - it does sound simple, so what are you leaving out? :)

Link to comment
Share on other sites

Sounds like you need to develop your html page with the input form.  The action of that form will call your php script which will grab the input fields from the form and do something with them.  At the end that same script will send some html back with the results of your inputs.  Yes - it does sound simple, so what are you leaving out? :)

 

yes, from one of the sample php html forms, i can post and display vars. but i have no idea what the data looks like coming from the server. i just what to display/print it in a blob on the response page. what var says, 'oh, a bunch of data, here!'?

Link to comment
Share on other sites

This data from the server - is it something you are creating or is it something that is stored somewhere and you are just pulling it up?  I don't think you want to display it in a blob either.  Can you be more specific about what transpires from the time your script retrieves the input values from the form?

Link to comment
Share on other sites

This data from the server - is it something you are creating or is it something that is stored somewhere and you are just pulling it up?  I don't think you want to display it in a blob either.  Can you be more specific about what transpires from the time your script retrieves the input values from the form?

 

 

sure, i'll explain. this is a for a test project. the company is running a lotus notes, domino server. they want to rebuild it because... well... obviously. the domino server will handle all the scripting and processing for now. i just need user forms to post vars to the server and handle the return data. part of the test is, i have no idea what the data looks like. i'm guessing its csv. parsing it is step two. i need to see what i'm working with. 

 

(is offering paypal change for help considered rude or bm?)

Link to comment
Share on other sites

Sorry - but without knowing what the data on the server is, how the heck are you going to program a retrieval?  Somebody has to give you some guidance there.  You can't just take a submitted form into your php script, assemble the inputs and then do ?what?.  Or are you given a script name that is already written which you need to send your input form to? If so, then that target script has to have a way of sending data back to you which again, you have to be ready to receive somehow.

 

You're not telling us something I believe.  Too much mystery

Link to comment
Share on other sites

i've been on reddit long enough to understand your skepticism. it is a mystery because its a test case; to see if i can get the data. 

 

i posted the test code here just as i received it, minus the actual url. they said, here are some vars, here the url to post to, now tell us what you see. the developer i spoke to said he didn't care what language i used. i have exposure to php (from years with joomla) so i'm trying this. again, maybe i'm overcompliating it. 

 

does php have a simple post and simple get script?

 

here are two sample i found i think i'm looking for:

<?php 
printArray($_POST);

/*
 * $pad='' gives $pad a default value, meaning we don't have 
 * to pass printArray a value for it if we don't want to if we're
 * happy with the given default value (no padding)
 */
function printArray($array, $pad=''){
     foreach ($array as $key => $value){
        echo $pad . "$key => $value";
        if(is_array($value)){
            printArray($value, $pad.' ');
        }  
    } 
}
?>



<?php 
if (${'_'.$_SERVER['REQUEST_METHOD']}) {
    $kv = array();
    foreach (${'_'.$_SERVER['REQUEST_METHOD']} as $key => $value) {
        $kv[] = "$key=$value";
    }
}
?>

but when i try with a form post, i get nothing.

 

here is the url i am using to test: http://jasonhoblin.com/userdata/connect/welcome.html

Edited by jasonhoblin
Link to comment
Share on other sites

The code above is very rudimentary and not very smart.  It will display the contents of the input vars from a submission.  Now what?

 

Much simpler code would be:

 

foreach($_REQUEST as $k=>$v)
    echo "$k contains $v<br>";

 

Since the REQUEST array contains whatever is in the GET or POST array, using it eliminates the guess work done above.  I eliminated the recursive code that was handling an array input within the REQUEST since from your example I don't think that will be an issue.

Edited by ginerjm
Link to comment
Share on other sites

The code above is very rudimentary and not very smart.  It will display the contents of the input vars from a submission.  Now what?

 

Much simpler code would be:

 

foreach($_REQUEST as $k=>$v)
    echo "$k contains $v<br>";

 

Since the REQUEST array contains whatever is in the GET or POST array, using it eliminates the guess work done above.  I eliminated the recursive code that was handling an array input within the REQUEST since from your example I don't think that will be an issue.

 

 

that code works in the test form! thank you. 

 

imma build up the test page to try to get the data. i'll post what happens. thanks again. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.