Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can I post form data without a form using PHP?

Posted on 2009-05-13
8
Medium Priority
?
405 Views
Last Modified: 2013-12-12
I have already collected the data to be sent to PayPal previously and would just like to go to PayPal for  processing the data without needing  someone to submit  a form.

<form action="https://www.paypal.com/au/cgi-bin/webscr" method="post">
 <input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="test@test.com.au">
 <input type="hidden" name="item_name" value="Sample Business -Invoice Payment">
 <input type="hidden" name="item_number" value="<?php echo "Invoice: ".$id; ?>">
 <input type="hidden" name="email" value="<?php echo $_POST['email']; ?>">
 <input type="hidden" name="quantity" value="1">                        
 <input type="hidden" name="amount" value="<?php echo $amount; ?>">
 <input type="hidden" name="invoice" value="<?php echo $id; ?>">
 <input type="hidden" name="first_name" value="<?php echo $_POST['first_name']; ?>">
 <input type="hidden" name="last_name" value="<?php echo $_POST['last_name']; ?>">
 <input type="hidden" name="address1" value="<?php echo $_POST['address1']; ?>">
 <input type="hidden" name="city" value="<?php echo $_POST['city']; ?>">
 <input type="hidden" name="state" value="<?php echo $_POST['state']; ?>">

I just need a way of automatically submittting or sending the data to PayPal, I hope this makes sense.

Thanks in advance for you help and feedback.
0
Comment
Question by:sabecs
[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
8 Comments
 
LVL 8

Expert Comment

by:mostart
ID: 24373807
hmm... sounds a bit strange to me. Someone needs to "push the button" in the end because otherwise you would not have any script run at all don't you ?

So if you already have all data, you could surely just open your php script in your browser, or run it on the command line to post your data to the PayPal API.

Still I'm not sure if I really understood your problem ??
0
 
LVL 5

Expert Comment

by:Pantalaim0n
ID: 24373840
Just put a little javascript after your form definition:

<script type="text/javascript">
document.forms[0].submit();
</script>

Open in new window

0
 
LVL 4

Expert Comment

by:max-hb
ID: 24373918
Hi,
to send POST-Vars you could directly connect to the foreign server and send your data using fputs(), see attached example code (taken from a german PHP FAQ).

All this script does is simulate form submission by "hand craftign" all necessary HTTP-params.

The example sends 2 parameters (pid, poll_vore_number) to the server www.linux.com.

Change the function call to PostToHost() to fit your needs.

Regards
 Marc

function PostToHost($host, $path, $referer, $data_to_send) {
  $fp = fsockopen($host, 80);
  printf("Open!\n");
  fputs($fp, "POST $path HTTP/1.1\r\n");
  fputs($fp, "Host: $host\r\n");
  fputs($fp, "Referer: $referer\r\n");
  fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n");
  fputs($fp, "Connection: close\r\n\r\n");
  fputs($fp, $data_to_send);
  printf("Sent!\n");
  while(!feof($fp)) {
      $res .= fgets($fp, 128);
  }
  printf("Done!\n");
  fclose($fp);
 
  return $res;
}
 
$data = "pid=14&poll_vote_number=2";
 
printf("Go!\n");
$x = PostToHost(
              "www.linux.com",
              "/polls/index.phtml",
              "http://www.linux.com/polls/index.phtml?pid=14",
              $data
);

Open in new window

0
Technology Partners: 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!

 

Author Comment

by:sabecs
ID: 24374099
Thanks for your feedback,
Basically I have an order form on a previous page that takes the users input and passes it to a PHP page that processes the order.  If the payment option selected by the customer is PayPal then I need the information they have already provided to go to PayPal so that they complete the payment process. If they did not select PayPal as their payment option then some other code will be executed.
0
 
LVL 8

Expert Comment

by:mostart
ID: 24374161
so then make your script which processes the users input go to Paypal in case paypal is selected.
0
 

Author Comment

by:sabecs
ID: 24381418
Thanks for your help, the inital order form is already complicated by validation and other code so would I prefer to keep the PayPal code on another page, it will only execute if PayPal is selected.
0
 
LVL 8

Accepted Solution

by:
mostart earned 2000 total points
ID: 24382254
well then create some kind of paypal.php put the paypal code inside and in case paypal is selected you just include that file:

include('paypal.php');
0
 

Author Closing Comment

by:sabecs
ID: 31580920
Thanks mostart for all your comments and help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 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