[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

cURL not working!

Asked by DrDamnit in PHP Scripting Language

I am attempting to use cURL to integrate a form into awebber.com, which usually uses it's own dynamically generated forms to signup people to an opt-in list.

I am having a case of user error. I have created a class to POST the form variables to their url, but it doesn't appear to be working.

Code snippet 1: This form works, but is a straight HTML POSTed form.
Code snippet 2: This is the class I wrote, but it doesn't POST the variables correctly.

What is wrong with the class?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
SNIPPET 1:
 
<form method="post" action="http://www.aweber.com/scripts/addlead.pl">
<input type="hidden" name="meta_web_form_id" value="1468401561">
    <input type="hidden" name="meta_split_id" value="">
    <input type="hidden" name="unit" value="jobhuntsuccess">
    <input type="hidden" name="redirect" value="http://www.aweber.com/form/thankyou_vo.html" id="redirect_89d25e6c2fded4b568b61d9895650a60">
    <input type="hidden" name="meta_redirect_onlist" value="">
    <input type="hidden" name="meta_adtracking" value="">
    <input type="hidden" name="meta_message" value="1">
    <input type="hidden" name="meta_required" value="from">
    <input type="hidden" name="meta_forward_vars" value="1"> 
<table><tr><td colspan=2><center><div>Uses http://www.guaranteedjobsystems.com/quiz/</div></center></td></tr><tr><td>Name:</td><td><input type="text" name="name" value="" size="20"></td></tr><tr><td>Email:</td><td><input type="text" name="from" value="" size="20"></td></tr>    <tr><td colspan=2><center></center></td></tr><tr><td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td></tr></table></form>
 
SNIPPET 2:
<?php
        //Uses cURL to send variables to aWebber.com to signup for a list.
class awebber {
 
        var $fields;
        var $values;
        var $ch;
        var $response;
        var $debug=false;
 
        function __construct($url = 'http://www.aweber.com/scripts/addlead.pl') {
                $this->fields = array();
                $this->values = array();
                $this->ch = curl_init($url);
//                curl_setopt($this->ch, CURLOPT_POSTFIELDS    ,$this->vars); //<-- Should be done in post_this instead.
//                curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION  ,1);
//                curl_setopt($this->ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
        }
 
        function add_var($field,$value) {
                //adds POST vars to the vars array
                //usage $x->add_var(field,value)
                array_push($this->fields,$field);
                array_push($this->values,$value);
        }
 
        function post_this() {
                //create array to hold variables
                $buffer = array();
 
                //Compile POST string
                for($i=0;$i<=sizeof($this->fields);$i++) {
                        $buffer[$i][0] = $this->fields[$i];
                        $buffer[$i][1] = $this->values[$i];
                }
 
 
                //executes the cURL post function.
//                curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: multipart/form-data"));
                curl_setopt($this->ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
                curl_setopt($this->ch,CURLOPT_POST,1);
                curl_setopt($this->ch, CURLOPT_POSTFIELDS    ,$this->build_url($fields,$values));
                $this->response = curl_exec($this->ch);
                if($this->debug) {
                        echo "<pre>";
                        print_r($this->build_url($fields,$values));
                        echo "</pre>";
                        echo $this->response;
                }
        }
 
        function build_url($fields,$values) {
                for($i=0;$i<=sizeof($fields);$i++) {
                        $buffer .= $fields[$i] . "=" . $values[$i];
                        if($i < sizeof($fields))
                        {
                                $buffer .= "&";
                        }
                }
                return urlencode($buffer);
        }
}
[+][-]08/06/09 05:49 PM, ID: 25039249Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/09 03:15 AM, ID: 25239458Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP Scripting Language
Sign Up Now!
Solution Provided By: DrDamnit
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_EXPERT_20070906