pixellegolas Posted October 1, 2019 Share Posted October 1, 2019 Hi guys! Total noob here that needs a bit of help creating a form. I have gotten this piece of code and want people to optin with Name and email. Let me send the code first: Request for PHP language: <?php $apiUrl = "https://udimi.com/api/affgen/addref"; $headers = [ "Content-Type: application/json", "Auth: MY AUTH CODE HERE" ]; $referral = [ 'fullname' => 'Referral Fullname', 'email' => 'refemail@domain.com' ]; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => $apiUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($referral), CURLOPT_HTTPHEADER => $headers ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } Success JSON response (HTTP status code: 200): {"error": false} Failed JSON response (HTTP status code: 200): {"error": "Pass identity verification and earn a commission as Udimi affiliate."} POST fields: fullname: required, 2-25 chars, only English letters. email: required So I figured I need to create a html file with a simple form, so I created this: <fieldset> <legend>Form</legend> <form action="test.php" method="post"> <label>Full Name: </label><input type="text" name="fullname" /><br /> <label>Email: </label><input type="text" name="email" /><br /> <input type="submit" name="submit" value="submit" /> </form> </fieldset> The problem is that I got it populate something when entering the form but the name was "Referral Fullname" as the code and the email was "refemail..." as the code. It did not grab my input. Any pointers here? Should I approach it in another way? Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/ Share on other sites More sharing options...
Barand Posted October 1, 2019 Share Posted October 1, 2019 Try this ... $referral = [ 'fullname' => $_POST['fullname'] ?? 'Referral Fullname', 'email' => $_POST['email'] ?? 'refemail@domain.com' ]; so that it uses the input data if it exists Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570163 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 Thanks, is the html code correct then with the name="fullname" etc? Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570164 Share on other sites More sharing options...
Barand Posted October 1, 2019 Share Posted October 1, 2019 Not pretty, but functions OK Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570165 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 updating with the code gets me a http error 500 code only Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570180 Share on other sites More sharing options...
Barand Posted October 1, 2019 Share Posted October 1, 2019 What php version are you using? Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570181 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 5.6 is installed on cpanel Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570182 Share on other sites More sharing options...
Barand Posted October 1, 2019 Share Posted October 1, 2019 Old versions will require... $referral = [ 'fullname' => (isset($_POST['fullname']) ? $_POST['fullname'] : 'Referral Fullname'), 'email' => (isset($_POST['email']) ? $_POST['email'] : 'refemail@domain.com') ]; Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570183 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 I have another host, will see what it has first, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570184 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 ah ok, thanks for that, will try and get back with result Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570185 Share on other sites More sharing options...
pixellegolas Posted October 1, 2019 Author Share Posted October 1, 2019 That worked like a charm! Thanks for the quick reply and help! A small donation might be in order Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570186 Share on other sites More sharing options...
Barand Posted October 1, 2019 Share Posted October 1, 2019 31 minutes ago, pixellegolas said: I have another host, will see what it has first, thanks! The second version (for v5.6) will still work with v7.0+ Quote Link to comment https://forums.phpfreaks.com/topic/309314-curl-noob-here/#findComment-1570188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.