Forum OpenACS Development: Variable number of elements in ad_form

Hello,

I am trying to create an ad_form that has one or more text input fields that can be created depending on the number of requirements pulled from the database.

so far i am pulling the number of text input fields needed for ad_form with a db_multirow and using var_name:rowcount to see how many text fields i will need, but var_name:rowcount will not work as the variable in a for statement and

set var var_name:rowcount

will not work either. The result is var is set to the text value var_name:rowcount.

any ideas?
thanks

here is my code:

db_multirow -unclobber -local -append evalu query {
SELECT req_bank_id
FROM jobs_req_map
WHERE position_id=:position_id
}

set form { eval_id:key(jobs_eval_id_seq)}

set num2 0
set row 3

for {set i 0} {$i < $row} {incr i} {

# incr $num2
lappend form {
{req$num2:text(text)
{label "Requirement Score"}
}
}

}


ad_form -name evals \
-cancel_url index \
-form { eval_id:key(jobs_eval_id_seq)
{req$num2:text(select)
{label "Requirement Score $num2"}
{options {{"" } {"5" 5} {"4" 4} {"3" 3} {"2" 2} {"1" 1} {"0" 0}}}
} } \
-new_data {

} -after_submit {
ad_returnredirect index
}

#{ eval_id:key(jobs_eval_id_seq)
# {req$num:text(select)
# {label "Requirement Score $num"}
# {options {{"" } {"5" 5} {"4" 4} {"3" 3} {"2" 2} {"1" 1} {"0" 0}}}
# } } \

Collapse
Posted by Dave Bauer on
Use template::multirow::size $multirow_name
after calling db_multirow to get the number of rows.
Collapse
Posted by Brad Poulton on
I was able to get this to work:

db_multirow evalu query {
SELECT req_bank_id
FROM jobs_req_map
WHERE position_id=:position_id
}

set form "\{ eval_id:key(jobs_eval_id_seq)"

set row [template::multirow size evalu]

for {set i 1} {$i <= $row} {incr i} {

set label "\"Requirement $i\""

append form " \{ req$i:text(text) {label $label}\} "

}

append form \}

ad_form -name evals \
-cancel_url index \
-form $form

This works, but the form has no text boxes. Can ad_form take a variable like this? I have check the string $form and it is correct syntax for ad_form.

Thanks, Brad

Collapse
Posted by Brad Poulton on
I ended up doing this:

db_multirow evalu query {
SELECT req_bank_id
FROM usurf_jobs_req_map
WHERE position_id=:position_id
}

ad_form -name evals \
-cancel_url index \
-form { eval_id:key(usurf_jobs_eval_id_seq)
{comments:text(textarea)
{label "Comments"}
}

}

for {set i 1} {$i <= ${evalu:rowcount}} {incr i} {

set label "Requirement $i"

ad_form \
-extend \
-name evals \
-form {
{ req_$i:text(select),optional {label $label} {options {{" " } {"5" 5} {"4" 4} {"3" 3} {"2" 2} {"1" 1} {"0" 0}}}}
}

}

the ad_form -extend worked great!