Forums

Admin Select Lists

kavaXtreme 25 Nov, 2008
I've got a couple of questions about select lists on an existing database that I'm hoping someone can help me with:

1. I'd like to do a select list for a Month field entry. The basic code is not the problem; it's my existing fields that are the challenge. How do I make the select list add "selected='selected'" to the correct option when I'm editing records since my existing fields (2,000+) are written out longhand. I think I could do it if I just knew the variable that contains the field value.

2. In another area of the form, I have a categories field. I'd like to have the option of selecting from an existing select list, or adding/editing a category myself. I know how to code it either way, but not how to have both options on a single form. (It seems to ignore both of them when I do that.) Here's the code I'm using:
        <td>Section:</td><td><input type="text" name="section" value=""></td>

or
        <td>Section:</td><td>
        <select name="section">
        <?php
            $database->setQuery( "SELECT DISTINCT section FROM table_name ORDER BY section ASC" );
            $sections = $database->loadObjectList();
            foreach($sections as $section){
        ?>
            <option value="<?php echo $section->section; ?>"><?php echo $section->section; ?></option>
        <?php } ?>
        </select>
        </td>
batmon 25 Nov, 2008
I have a similar question. I actually using CF as the "add new record" form. My form has some fields using drop down list for selection. I use CC to create a table list view. I have "edit" link so that users can edit the record. How do I handle drop down select field and how to read the record and add the "selected"?

Thank you.
Max_admin 25 Nov, 2008
Hi,

Adding any HTML code in the frontend edit code box will get processed and this php will be added by Chronoforms automatically, if this doesn't work then show me your code!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
batmon 25 Nov, 2008
Okay, for me my "ADD" form is


Division: <select class="cf_inputbox validate-selection" id="select_2" size="1" name="select_2">
  <option value="DivisionA">DivisionA</option>
  <option value="DivisionB">DivisionB</option>
  <option value="DivisionC">DivisionC</option>
  <option value="DivisionD">DivisionD</option>
  <option value="DivisionE">DivisionE</option>
  <option value="DivisionF">DivisionF</option>
</select>


Let say I added a record with "DivisionC" selected. How should I write my code for frontend and backend edit page so the edit will default (selected) with "DivisionC"?

Thank you.
batmon 25 Nov, 2008
Nevermind, I see how it works now... Thanks.
kavaXtreme 25 Nov, 2008
My questions still stand if anybody has some feedback. The code for question 1 would look something like this:
<?php
$curr_month = [existing field value];
$month = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"month\">\n";
foreach ($month as $key => $val) {
    $select .= "\t<option val=\"".$key."\"";
    if ($key == $curr_month) {
        $select .= " selected>".$val."\n";
    } else {
        $select .= ">".$val."\n";
    }
}
$select .= "</select>";
echo $select;
?>

I just don't know how to get [existing field value].
batmon 25 Nov, 2008
FYI, I use HTML codes, not PHP, but it might apply to PHP too.

You don't have to worry about the "selected" keyword, CC will magically does this for you.

Just have <option value="January">January</option> through out and it works for me.

Hope this help.
Max_admin 25 Nov, 2008
Hi kavaXtreme,

as batmon said, remove this PHP and add a static code and it will work with the value stored in this record!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
cubefree 10 Nov, 2009
I am using ChronoConnectivity_V2_RC3.zip with Chronosforms (of course) with Joomla 1.5.11.

I did get only some of the magic you refer to, but still love this component!!

In my case, the selected form does NOT highlight the selected option in the select drop-down input WHEN editing an existing record in the admin area: show data.

I have confirmed that while editing the record AND NOT selecting any drop-down, CC keeps data intact. OR if do select, the proper value is inserted in the table column.

HOWEVER when I go to edit existing records, the drop-down selection is NOT selected ( and therefore appears as if a selection was NEVER made).

Additionally, I have confirmed in FireBug that 'selected' is no where in the form's contents. Therefore IF I use validate-selection, I get a warning EVEN though the table column does contain data.
GreyHead 10 Nov, 2009
Hi cubefree,

I'm not sure how to help here - you've linked to a year old thread. I don't use the CC admin edit and short of hunting in the code I don't know how to check this. (I tend to create my own forms to do the editing in the front-end.)

Bob
cubefree 10 Nov, 2009
Well yes, sorry I missed the date... of course it is not so relevant. I can create an admin username/pw if you want to confirm my findings.

Btw, I did purchase one license, but have lost the relevant info to validate. In any case, this is for another client, so I'd happily get another one.
This topic is locked and no more replies can be posted.