Forum OpenACS Q&A: Newbie - How to create a drop-down list?

Collapse
Posted by Daniel D on
Hello All,

I am using "ad_form" function in my *.tcl file. I do have
this code:

ad_form -name d-bug_project_edit -form {
    project_id:key(dbg_dbg_id_sq)
    {description:text(textarea)
        {label "Description"}
    }
    {maintainer:integer
        {label "Maintainer"}
    }

And I would like to have a drop down list consisting of all user names (first_names, last_name) from cc_users table instead of that "Maintainer field". My friend had show me how to do it using code in *.adp page, is it possible to do it in *.tcl, maybe utilizing the "ad_form" function?

Thank you for your time.

DanielD

Collapse
Posted by Daniel D on
Hello Jon,

With this sample I was able to create the drop down list. However I do have an additional problem. How it works now:

I have the first_names||' '||last_name in drop down menu. By selecting a name, I pass an object_id to the DB table "project". However, I would like to pass an additional paramater - a coresponding email to the email_sub_name in the same table...

Thank you for your time.

DanielD

Here is the code I have so far:

("Maintainers" query has a column, "email". But how to pass this value to different column in project table?)

ad_page_contract {
        Simple add/edit form for d-bug_project.
} {
    {project_id:integer,optional}
}
set user_id [ad_maybe_redirect_for_registration]
set title "Add a Project"
set maintainers [db_list_of_lists get_maintainers "SELECT first_names||' '||last_name, email, object_id FROM cc_users;"]

if {[exists_and_not_null project_id]} {
    set title "Edit a Project"
}

ad_form -name d-bug_project_edit -form {
    project_id:key(dbg_dbg_id_sq)
    {description:text(textarea)
        {label "Description"}
    }
    {maintainer:text(select)
        {label "Maintainer"} { options {$maintainers} {value $object_id}}
    }
} -select_query {
    SELECT *
    FROM  project
    WHERE  project_id = :project_id
} -new_data {
db_dml do_insert_project "
      INSERT INTO project
      VALUES      (
                  :project_id,
                  :description,
                  :maintainer,
                  :email,
                  :user_id
                  )
"
} -edit_data {
db_dml do_update_project "
      UPDATE project
      SET    project_id    = :project_id,
              description    = :description,
              maintainer    = :maintainer,
              email_sub_name = :email,
              creator        = :user_id
      WHERE  project_id    = :project_id"
} -after_submit {
ad_returnredirect "index"
}

Collapse
Posted by Jade Rubick on
I personally couldn't figure out what it was you're trying to do. Perhaps you can explain it again, in more detail?