php forms return data back to .html page -
this should pretty simple questions can't seam find simple answer. of questions find deal same jquery.
i have php page accepts post data, places in array, passes array api, , receives success/error api.
i have html page form. when submit form passes form data php file.
all return success/error message's variable html file. don't care if page reloads, don't want fancy features i'm trying simple test have forgotten php 101. or direction references appreciated.
html:
<div style="width: 400px; margin: 150px auto;"> <form action="api3.php" method="post"> <input type="text" placeholder="first name" name="fname"><br><br> <input type="text" placeholder="last name" name="lname"><br><br> <input type="email" placeholder="email" name="email"><br><br> <input type="text" placeholder="phone" name="phone"><br><br> <select name="life"><br><br> <option value="customer">customer</option> <option value="lead">lead</option> <option value="subscriber">subsciber</option> <option value="opportunity">opportunity</option> </select><br><br> <input type="text" placeholder="pizza" name="pizza"><br><br> <input type="submit" value="submit"> </form> </div>
php:
<?php $arr = array( 'properties' => array ( array( 'property' => 'email', 'value' => $_post["email"] ), array( 'property' => 'firstname', 'value' => $_post["fname"] ), array( 'property' => 'lastname', 'value' => $_post["lname"] ), array( 'property' => 'phone', 'value' => $_post["phone"] ), array( "property" => "lifecyclestage", "value" => $_post["life"] ), array( "property" => "pizza", "value" => $_post["pizza"] ) ) ); $post_json = json_encode($arr); $hapikey = "/"; $endpoint1 = 'http://api.hubapi.com/contacts/v1/contact/createorupdate/email/' . $arr['properties'][0]['value'] . '/?hapikey=' . $hapikey; $endpoint2 = 'http://api.hubapi.com/contacts/v1/lists/5/add?hapikey=' . $hapikey; $ch = @curl_init(); @curl_setopt($ch, curlopt_post, true); @curl_setopt($ch, curlopt_postfields, $post_json); @curl_setopt($ch, curlopt_url, $endpoint1); @curl_setopt($ch, curlopt_httpheader, array('content-type: application/json')); @curl_setopt($ch, curlopt_returntransfer, true); $response1 = @curl_exec($ch); $status_code1 = @curl_getinfo($ch, curlinfo_http_code); $curl_errors1 = curl_error($ch); if ($status_code1 == 200) { $vid = json_decode($response1, true); echo $vid['vid'] . '<br><br><br>'; $arr2 = array( 'vids' => array ( $vid['vid'] ) ); $vids_push = json_encode($arr2); @curl_setopt($ch, curlopt_postfields, $vids_push); @curl_setopt($ch, curlopt_url, $endpoint2); $response2 = @curl_exec($ch); $status_code2 = @curl_getinfo($ch, curlinfo_http_code); $curl_errors2 = curl_error($ch); @curl_close($ch); return $response2; } ?>
edit: changed form.html page .php. didn't want share code because seams complicate things want return $response2 form.php page.
first of page have form , want response should .php
now example, have page form @ www.example.com/work.php
//your form here <form> </form>
submit form on other .php page process input , response api. @ end of page have 2 methods return data.
using encode variables in url , redirect page work.php
$url = "www.example.com/work.php" + "?status=error&message=this message"; header('location: '.$url);
now on work.php file need utilize these parameters encoded url using
echo $_get['status']; echo $_get['message']; // rest of page same.
- using session
store variables in session , redirect work.php without parameters
$_session['status'] = "error"; $_session['message'] = "this message"; $url = "www.example.com/work.php"; header('location: '.$url);
again in work.php file display data session , rest of code same.
Comments
Post a Comment