Hi,
I would like to know how to pull data into a form text box. I have tried using profile plugin, but it is not working. I have a new form, and I need to display information coming from another table. I've tried using the code below, but I don't think i have the format is correct. Thanks for helping
I would like to know how to pull data into a form text box. I have tried using profile plugin, but it is not working. I have a new form, and I need to display information coming from another table. I've tried using the code below, but I don't think i have the format is correct. Thanks for helping
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Driving License State*</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="drivers state" id="text_11" name="state" type="text" />
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$user = JFactory::getUser('id');
$query = "
SELECT state
FROM `#__chronoforms_registration`
WHERE `cf_user_id` = ".$user->id.";
";
$db->setQuery($query);
$d = $db->loadObject();
if ( count($d) ) {
echo "<input type='hidden' name='cf_id' id='cf_id' value='".$d->cf_id."'/>";
}
?>
</div>
<div class="cfclear"> </div>
</div>
Hi about 2flip,
You query SELECT state gets one column value - for the state column.
But when you try to output the value you try to output the value of cf_id - value='".$d->cf_id."'. You haven't got the from the database so it will always be blank (or give you an error).
Bob
You query SELECT state gets one column value - for the state column.
But when you try to output the value you try to output the value of cf_id - value='".$d->cf_id."'. You haven't got the from the database so it will always be blank (or give you an error).
Bob
Ok. So what should I do to fix this? Can you show me.
Thanks
Thanks
Hi about2flip,
Read my post carefully, think about it and then correct the bugs in your code.
Bob
Read my post carefully, think about it and then correct the bugs in your code.
Bob
ok.
However it is not placing the data in the input textbox.
do i need `` back tick around select state, cf_id.
Do I still keep this line in:
does this line place this into the textbox:
Can you at least give me a hint, or something PLEASE. -Thanks
SELECT state, cf_id
However it is not placing the data in the input textbox.
do i need `` back tick around select state, cf_id.
Do I still keep this line in:
<input class="cf_inputbox required" maxlength="150" size="30" title="drivers state" id="text_11" name="state" type="text" />
does this line place this into the textbox:
echo "<input type='hidden' name='cf_id' id='cf_id' value='".$d->cf_id."'/>";
Can you at least give me a hint, or something PLEASE. -Thanks
Hi about2flip,
You don't *need* backticks here but better to get into the habit of adding them.
You need to add a value=' . . . ' entry to the state input if you want to display the value you have got from the database. But what goes in place of . . . ???
The hidden input will carry the value of cf_id into the form results.
Bob
You don't *need* backticks here but better to get into the habit of adding them.
You need to add a value=' . . . ' entry to the state input if you want to display the value you have got from the database. But what goes in place of . . . ???
The hidden input will carry the value of cf_id into the form results.
Bob
ok Professor Bob,
I played around with my assignment, since you refused to help me. I got it working. Can you correct my code to make sure it makes sense. -Thanks for not helping, it helps my programming skills.
I played around with my assignment, since you refused to help me. I got it working. Can you correct my code to make sure it makes sense. -Thanks for not helping, it helps my programming skills.
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Driving License State*</label>
<?php
$user =& JFactory::getUser();
$user_id = $user->get('id');
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
SELECT `state`
FROM `#__chronoforms_registration`
WHERE `cf_user_id` = ".$user->id.";
";
$db->setQuery($query);
$d = $db->loadObject();
if ( count($d) ) {
echo "<input type='text' size='30' name='state' id='cf_id' value='".$d->state."'/>";
}
?>
</div>
<div class="cfclear"> </div>
</div>
Bob,
I just realized that if that column is empty it creates an extra textbox. How can I stop that from happening. Do I use an if statement?
Thanks
I just realized that if that column is empty it creates an extra textbox. How can I stop that from happening. Do I use an if statement?
Thanks
Hi about2flip,
The code looks good. A few small tweaks:
[list]I'd change the input id from 'cf_id' to 'state' just to be tidy
This line is no longer doing anything $user_id = $user->get('id'); so could be removed
The $mainframe->isSite() line is only needed for some versions before CFv3.2; if it appears it should be immediately after the first <?php tag. Here I think it can be deleted. [/list]
Please say a bit more about the 'extra text box'? I'm not clear what the problem is.
Bob
The code looks good. A few small tweaks:
[list]
Please say a bit more about the 'extra text box'? I'm not clear what the problem is.
Bob
This topic is locked and no more replies can be posted.