Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:52:59+00:00 2026-06-04T04:52:59+00:00

I have to post to a URL using PHP. right now it works but

  • 0

I have to post to a URL using PHP. right now it works but after the sending data/posting, it gives gives a json output (from the web service i’m posting to) and i need the output to be friendly.
I can’t use jquery with ajax because it’s conflicting. i need to communicate directly to the web service

Here’s my form:

<form action="http://somewebservice.com/<?php echo $PrizeID;?>" method="post" name="myform">
<input name="account" id="account" type="hidden" value="<?php echo $account;?>"/>
<input name="dob" id="dob" type="hidden"  value="<?php echo $dob;?>"/>
<input name="site" id="site" type="hidden"  value="<?php echo $site;?>"/>
<input name="submit" type="submit" value="submit"/>
</form>

after clicking submit it takes me to a page with the following JSON output:

{"Prize":"XXXXXX","ConfirmationCode":"######","Error":false,"ErrorMsg":null}

The posting works ok because i ckeck the web service logs and the submission is registered. all i need to do now is to show the ConfirmationCode from the piece above nicely formatted instead of the whole JSON output.
Any help would be greatly appreciate it.

UPDATE
i made some changes based on ur help…
it refreshes the page but doesn’t update the db. i checked the web service log and no entry is recorded.
it gives me bool(false) as error and when ECHOing $context, i get “Resource id#4”

here’s the updated form:

<form name="myform">
<input name="account" id="account" type="hidden" value="<?php echo $account;?>"/>
<input name="dob" id="dob" type="hidden"  value="<?php echo $dob;?>"/>
<input name="site" id="site" type="hidden"  value="<?php echo $site;?>"/>
<input name="submit" type="submit" value="submit"/>
</form>

here’s the PHP

if(isset($_POST['submit'])){
$options = array(
            'http'=>array(
                'method'=>"POST",
                'contentType'=> "application/x-www-form-urlencoded",
                'content'=>http_build_query(array(
                        'account' => $account,
                        'dob' =>   $dob,
                        'site' => $site
                    ))
            ));

        $context = stream_context_create($options);
        $result =  file_get_contents("http://somewebservice.com/{$PrizeID}",NULL,$context);
        var_dump($result);
}

Update (w/AJAX)
I tried ajax and i while it writes to the web service, i get an error in the clietn site. the error says [object Object]
here’s the ajax

here’s the form

<form name="myform" >
<input name="account" id="account" type="hidden" value="<?php echo $account;?>"/>
<input name="dob" id="dob" type="hidden"  value="<?php echo $dob;?>"/>
<input name="site" id="site" type="hidden"  value="<?php echo $site;?>"/>
<input id="submit" type="submit" value="submit"/>
<div id="result"></div>

here’s the ajax script:

<script type="text/javascript">
$("#submit").click(function(e){
    e.preventDefault(); 
    var account = $('#account').val();
    var dob = $('#dob').val();
    var site = $('#site').val();

    $.ajax({
        type: "POST",
        url: "http://somewebservice.com/<?php echo $PrizeID;?>",
        data: "{ 'account': '" + account + "','dob': '" + dob + "', 'site': '" + site + "'}",
        contentType: "application/json; charset=utf-8",
        async: false,
        success: function(data) {
            //$('#result').text(data.d);
            alert(data);
            var obj = $.parseJSON(data);
                $("#result").html("<p><b>Confirmation Code:</b> " + obj.ConfirmationCode + "</p>");
        },
        error: function(data) {
            alert(data);
            $("#result").html("<b>There was an error. Please try again</b><br/>");

        }
    });
});
</script>

UPDATE (w/Curl) – SOLVED – IT WORKS !!!!
This works – it posts to the database via the web service and i’m able to get back the ConfirmationCode returned by the webservice.

Here’s the form in offer.php

<form action="process.php" method="post" name="myform">
<input id="submit" type="submit" value="submit"/>
</form>

here’s the process.php file

<?php
$data = array("account" => "{$account}", "dob" => "{$dob}", "site" => "{$site}");                                                                    
$data_string = json_encode($data); 

$ch = curl_init("http://somewebservice.com/{$PrizeID}");                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                   
$result = curl_exec($ch);                            
curl_close($ch);
$json_result = json_decode($result, true);
?>
// here's the call for the confirmation number
<p>Your confirmation number is: <strong><?php echo $json_result['ConfirmationCode'];?></strong></p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:53:00+00:00Added an answer on June 4, 2026 at 4:53 am

    You could create a PHP script to act as a proxy to the web service which then formats the returned JSON as you require.

    Your form tag would change to:

    <form action="http://myaddress.com/myproxyscript.php" method="post" name="myform">
    

    and then myproxyscript.php would be something like:

    <?php
    $postvars=file_get_contents("php://input");
    
    $curl=curl_init("http://somewebservice.com/{$PrizeID}");
    curl_setopt($curl,CURLOPT_POSTFIELDS,$postvars);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    $result=curl_exec($curl);
    $decodedresult=json_decode($result,true);
    // do stuff with result here...
    ?>
    

    or you could use file_get_contents in the PHP to fetch the result as given in Tufan’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
In my document I have this script: $.ajax({ type:POST,url:ajax.php,data:data, success: function() { //onsuccess },
Using jquery, i fetch a data from php to div $.post(url.php?info=+$('#info').val() // rest of
Does anyone have some sample code showing how to POST to a URL using
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I have the following restful api ajax call: $.ajax({ type: POST, url: https://website.com/a/login, data:
right now i m using this code for playing youtube videos <?php // Replace
let say I have a post that can be found on page post.php?pid=60 but
I have to POST some parameters to a URL outside my network, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.