I have a form that collects lead data and on submit I want that info to go to MYSQL and a Webhook.
I've got to pieces of PHP code (MYSQL-WEBHOOK.PHP AND WEBHOOK.PHP) that I've created for testing in the <The form action="">
Here is the HTML for the form
<form action="/Lead/leadprocess.php">
<div class="row">
<div class="col-25">
<label for="VehVin">Vehicle VIN Number - Please Verify</label>
</div>
<div class="col-75">
<input type="text" id="VehVin" name="VehVin" placeholder="Vehicle Vin Number">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="Own1st">Applicants First Name</label>
</div>
<div class="col-75">
<input type="text" id="Own1st" name="Own1st" placeholder="Your First Name..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="OwnLst">Applicants Last Name</label>
</div>
<div class="col-75">
<input type="text" id="OwnLst" name="OwnLst" placeholder="Your Last Name..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="OwnPh">Applicants Mobile Number</label>
</div>
<div class="col-75">
<input type="text" id="OwnPh" name="OwnPh" placeholder="Your Mobile Number..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="OwnEml">Applicants Email Address</label>
</div>
<div class="col-75">
<input type="text" id="OwnEml" name="OwnEml" placeholder="Your Email Address..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="OwnSt">State Of Residence</label>
</div>
<div class="col-75">
<select id="OwnSt" name="OwnSt">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="Serv">State Of Residence</label>
</div>
<div class="col-75">
<select id="Serv" name="Serv">
<option value="Title Transfer">Title Transfer</option>
<option value="Title Replacement">Title Replacement</option>
<option value="Bonded Title">Bonded Title</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="Coments">Comments</label>
</div>
<div class="col-75">
<textarea id="Coments" name="Coments" placeholder="Tell Us A Bit About Your Issue.." style="height:200px"></textarea>
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
I trying to use this code to pass info from the URL as variables, convert it to json and send it to the webhook and then redirect to a thankyou page. Hoping to use this code to test the webhook for a successful trigger catch.
FILE NAME: WEBHOOK.PHP
<?php
$VehVin = $_GET['VehVin'];
$Own1st = $_GET['Own1st'];
$OwnLst = $_GET['OwnLst'];
$OwnPh = $_GET['OwnPh'];
$OwnEml = $_GET['OwnEml'];
$OwnSt = $_GET['OwnSt'];
$S3rv = $_GET['S3rv'];
$C0m3nts = $_GET['Coments'];
function generateKey() {
global $conn;
$keyLength = 9;
$str = "1234567890ABCDEFGHJKLMNPQRSTUVWXYZ";
$checkKey=true;
while ($checkKey == true) {
$randstr = substr(str_shuffle($str),0,$keyLength);
return $randstr;
}
}
$RefCod = generateKey();
$curl = curl_init();
$url = 'https://hooks.zapier.com/hooks/catch/9259009/o0txxca/';
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => [
'Contact._VehicleID' => '$VehVin',
'contact.first_name' => '$Own1St',
'contact.last_name' => '$OwnLst',
'Contact.Phone1' => '$OwnPh',
'Contact.Email' => '$OwnEml',
'Contact._IDStateofOrigin' => '$OwnSt',
'Contact._Service' => '$S3rv',
'Contact._Comments' => '$Com3nt',
'~Contact._RefCod~' => '$RefCod',
],
]);
$response = curl_exec($curl);
if ($error = curl_error($curl)) {
throw new Exception($error);
}
curl_close($curl);
$response = json_decode($response, true);
var_dump('Response:', $response);
/* Redirect browser */
header("Location: /Lead/shrtthks.html");
exit();
?>
I'm trying to use this code to send data to the MYSQL, then the Webhook, and then redirect to the thankyou page.
File name MYSQL-WEBHOOK.PHP
<?php
require_once('dogs.php');
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$conn){
echo 'Not Connected to Server';
}
if(!mysqli_select_db($conn, 'thetitl1_losttitl'))
{
echo 'Database Not Selected';
}
$VehVin = $_GET['VehVin'];
$Own1st = $_GET['Own1st'];
$OwnLst = $_GET['OwnLst'];
$OwnPh = $_GET['OwnPh'];
$OwnEml = $_GET['OwnEml'];
$OwnSt = $_GET['OwnSt'];
$S3rv = $_GET['S3rv'];
$C0m3nts = $_GET['Coments'];
function generateKey() {
global $conn;
$keyLength = 9;
$str = "1234567890ABCDEFGHJKLMNPQRSTUVWXYZ";
$checkKey=true;
while ($checkKey == true) {
$randstr = substr(str_shuffle($str),0,$keyLength);
// New random key is created, verify it is unique
$sql = "SELECT * FROM leadform WHERE refcod=" . $randstr;
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($conn,$result)==0) {
$checkKey=true;
} else {
$checkKey=false;
}
return $randstr;
}
}
$RefCod = generateKey();
$stmt = mysqli_prepare($conn, "INSERT INTO leadform VALUES (?,?,?,?,?,?,?,?,?)");
mysqli_stmt_bind_param($stmt, 'sssssssss', $VehVin,$Own1st,$OwnLst,$OwnPh,$OwnEml,$OwnSt,$S3rv,$C0m3nts,$RefCod);
/* execute prepared statement */
mysqli_stmt_execute($stmt);
/* Send form data to webhook using cURL and JSON*/
$curl = curl_init();
$url = 'https://hooks.zapier.com/hooks/catch/9259009/o0txxca/';
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => [
'Contact._VehicleID' => '$VehVin',
'contact.first_name' => '$Own1St',
'contact.last_name' => '$OwnLst',
'Contact.Phone1' => '$OwnPh',
'Contact.Email' => '$OwnEml',
'Contact._IDStateofOrigin' => '$OwnSt',
'Contact._Service' => '$S3rv',
'Contact._Comments' => '$Com3nt',
'~Contact._RefCod~' => '$RefCod',
],
]);
$response = curl_exec($curl);
if ($error = curl_error($curl)) {
throw new Exception($error);
}
curl_close($curl);
$response = json_decode($response, true);
var_dump('Response:', $response);
/* close statement and connection */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($conn);