Forum OpenACS Q&A: ad_form: Element 'dealer_id' already exists in form 'dealer'.

Initial try with ad_form, and I keep getting this error:

Element 'dealer_id' already exists in form 'dealer'.
        while executing
    "error "Element '$element_id' already exists in form '$form_id'.""
        (procedure "template::element::create" line 18)
        invoked from within
    "template::element::create dealer dealer_id -datatype integer -widget hidden"
        ("eval" body line 1)
        invoked from within
    "eval template::element::$command $form_id $element_id $args"
        (procedure "template::element" line 2)
        invoked from within
    "template::element create dealer dealer_id -datatype integer -widget hidden"
        ("eval" body line 1)
        invoked from within
    "eval $form_command"
        (procedure "ad_form" line 341)
        invoked from within
    "ad_form -name dealer -export {dealer_id} -form {

        dealer_id:key(moto_dealer_id_seq)

        {dealer_name:text(text)            {label "Deale..."
        ("uplevel" body line 22)
        invoked from within
    "uplevel {
              ad_page_contract {

        Simple add/edit form

    } {
        dealer_id:optional
    }

Form....

ad_page_contract {

    Simple add/edit form

} {
    dealer_id:integer,notnull,optional
}

if { ![ad_form_new_p -key dealer_id]} {
    set action "Edit"
} else {
    set action "Add"
}

set page_title "$action Dealer"
set package_id [ad_conn package_id]
set context [list [list "../dealer/" Dealer] "$action Dealer"]

ad_form -name dealer -form {

    dealer_id:key(moto_dealer_id_seq)

    {dealer_name:text(text) {label "Dealer Name"} {html {size 30}}}

} -select_query {
    select dealer_name from moto_dealer where dealer_id = :dealer_id
} -validate {
    {dealer_name
    {[string length $dealer_name] >= 3}
    "\"dealer_name\" must be a string containing three or more characters"
}
} -new_data {
    db_dml do_insert "
    insert into moto_dealer
    (dealer_id, dealer_name)
    values
    (:dealer_id, :dealer_name)"
} -edit_data {
    db_dml do_update "
    update moto_dealer
    set dealer_name = :dealer_name
    where moto_dealer = :dealer_id"
} -after_submit {
    ad_returnredirect "/"
    ad_script_abort
}

NVM -- I got it working.

How do you set a default value for a form element in ad_form? Setting value doesn't seem to work.

NVM again -- misplaced bracket, but it wasn't giving an error.