Based on 1 user-input field I want to populate multiple fields in a database table. See code below: I would like at assign $Relatienummer to hidden input field "relatienummer" and $Achternaam to "naam" and then submit. Any suggestions on how to do it?
<input value="" id="hidden_10" name="relatienummer" type="hidden" />
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Naam :</label>
<?php
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `Ledenbestand`
ORDER BY Achternaam";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
<select class="cf_inputbox validate-selection" id="select_11" size="1" title="" name="naam">
<?php
foreach ($rows as $row) {
echo "<option value='$row->Relatienummer'>$row->Achternaam $row->Relatienummer</option>";
}
?>
</select>
</div>
<div class="cfclear"> </div>
</div>
Hi JvdStel,
Assuming that 'Relatienummer' is a unique reference you can do this in the ONSubmit Before Email box:
Bob
NB: This is code for CFv3
Assuming that 'Relatienummer' is a unique reference you can do this in the ONSubmit Before Email box:
<?php
$Relatienummer = JRequest::getString('naam', '', 'post');
$Achternaam = '';
if ( $Relatienummer ) {
$db =& JFactory::getDBO();
$query = "
SELECT `Achternaam`
FROM `Ledenbestand`
WHERE `Relatienummer` = '$Relatienummer' ;
$db->setQuery($query);
$Achternaam = $db->loadResult();
}
JRequest::setVar('Achternaam', $Achternaam);
?>
(You already have $Relatienummer in the form data.Bob
NB: This is code for CFv3
Thanks Greyhead
Somehow I can't get the code in the "onsubmit - before email" to work..
Can you indicate what's wrong with it?
I have defined (part of) a form as follows:
In Onsubmit I have:
I have set a DB connect to a table called "Kleding". When I check the result after a submit of the form, "relatienummer" is filled all right (from the form code), but the "naam" field (from the onsubmit code) is left blank, where "Achternaam" in `CKC_Ledenbestand` exists. What am I doing wrong?
Somehow I can't get the code in the "onsubmit - before email" to work..
Can you indicate what's wrong with it?
I have defined (part of) a form as follows:
<input value="" id="hidden_10" name="naam" type="hidden" />
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Relatienummer :</label>
<?php
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `CKC_Ledenbestand`
ORDER BY Achternaam";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
<select class="cf_inputbox validate-selection" id="select_11" size="1" title="" name="relatienummer">
<?php
foreach ($rows as $row) {
echo "<option value='$row->Relatienummer'>$row->Achternaam $row->Voorletters $row->Tussenvoegsel $row->Relatienummer</option>";
}
?>
</select>
</div>
<div class="cfclear"> </div>
</div>
In Onsubmit I have:
<?php
$Relatienummer = JRequest::getString('relatienummer', '', 'post');
$Achternaam = '';
if ( $Relatienummer ) {
$db =& JFactory::getDBO();
$query = "
SELECT `Achternaam`
FROM `CKC_Ledenbestand`
WHERE `Relatienummer` = '$Relatienummer' ;
$db->setQuery($query);
$Achternaam = $db->loadResult();
}
JRequest::setVar('naam', $Achternaam);
?>
I have set a DB connect to a table called "Kleding". When I check the result after a submit of the form, "relatienummer" is filled all right (from the form code), but the "naam" field (from the onsubmit code) is left blank, where "Achternaam" in `CKC_Ledenbestand` exists. What am I doing wrong?
Hi JvdStel,
Is 'Send Emails' set to Yes on the Form general tab? If not then the OnSbmit Before Email code doesn't run.
Bob
Is 'Send Emails' set to Yes on the Form general tab? If not then the OnSbmit Before Email code doesn't run.
Bob
No, it was not (I am not sending any emails). But when I do, I get a parse error (twice):
Parse error: syntax error, unexpected $end in /www/v/v/c/vvckc.nl/public_html/Test1/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 14
Hi JvdStel,
I think that's because of a missing "; at the end of the query here
Bob
I think that's because of a missing "; at the end of the query here
if ( $Relatienummer ) {
$db =& JFactory::getDBO();
$query = "
SELECT `Achternaam`
FROM `CKC_Ledenbestand`
WHERE `Relatienummer` = '$Relatienummer' ;
"; // <-- add this line
$db->setQuery($query);
$Achternaam = $db->loadResult();
}
Bob
This topic is locked and no more replies can be posted.