I am trying to get some data from the form before its submitted to the DB. In my form the user selects a name from a drop down menu. I want to use a custom html field to query another table and get the email address that matches the name from the form and then submit it as another field in the form. My custom html code looks like this:
<?php
$servername = "localhost";
$username = "*******";
$password = "********";
$dbname = "*********";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$buyer = $form->data['PurchaseRequest']['buyer'];
$qbmail = "SELECT `rev3_chronoforms_data_Buyers`.`buyer`
FROM `rev3_chronoforms_data_Buyers`
WHERE `rev3_chronoforms_data_Buyers`.`buyer` = $buyer";
$bmailv = $conn->query($qbmail);
while($ebmail = $bmailv->fetch_array())
$bmail = end($ebmail);
$conn->close();
echo "<input type=\"hidden\" name=\"bmail\" value=\"$bmail\">";
?>
Unfortunately this does not work. To try and figure out why, I simplified it and just tried to get the name to save to the bmail field by using this code:
<?php
$servername = "localhost";
$username = "xxxxxxx";
$password = "xxxxxxxxxx";
$dbname = "xxxxxxxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$bmail = "$form->data['PurchaseRequest']['buyer']";
$conn->close();
echo "<input type=\"hidden\" name=\"bmail\" value=\"$bmail\">";
?>
In the debugger, I can see it is writting [bmail] => Array['PurchaseRequest']['buyer'] instead of the value.
Data Array:
Array
(
[chronoform] => PurchaseRequest
[event] => submit
[Itemid] => 831
[option] => com_chronoforms
[view] => form
[qty] => 9
[itemn] => gjk
[description] => bjk.
[Vendor] => Wal-Mart
[sup] => tom smith
[buyer] => Barney Rubble
[uname] => xxxx Admin
[uemail] => admin@xxxx.ca
[bmail] => Array['PurchaseRequest']['buyer']
[input_submit_8] => Submit
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] => 1
[chronoform_data] => Array
(
[cf_uid] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[cf_created] => 2015-06-04 12:34:53
[cf_created_by] => 42
[cf_ipaddress] => 192.168.x.xx
[cf_user_id] => 42
[chronoform] => PurchaseRequest
[event] => submit
[Itemid] => 831
[option] => com_chronoforms
[view] => form
[qty] => 9
[itemn] => gjk
[description] => bjk.
[Vendor] => Wal-Mart
[sup] => tom smith
[buyer] => Barney Rubble
[uname] => xxxx Admin
[uemail] => admin@xxxx.ca
[bmail] => Array['PurchaseRequest']['buyer']
[input_submit_8] => Submit
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] => 1
[cf_id] => 27
)
[chronoform_data_cf_id] => 27
Any help would be greatly appreciated.