Ah okay.
First: NEVER NEVER NEVER NEVER use sql in templates! You're using the
model correctly already to retrieve the list, but put the
mysql_fetch_array call into the model, too, and make it return an
array of ids and values:
<select name="qstID">
<option>Select</option>
<?php foreach($template['qstlist'] as $id => $value): ?>
<option value="<?=$id?>"><?=$value?></option>
<?php endforeach; ?>
</select>
The reason why your select list was empty on form submit is because
the action's executeRead() method runs only on GET, not on POST, so
add the getModel()->blah call to executeWrite(), too, or put it into
a common method that you call from both executeRead() and executeWrite
().
But back to the form. You don't have to select elements by hand or
fill in text field values. You can use the form population filter. It
automatically runs on POST (have you enabled it?), but you can make
it run on any other request method, too. In your example, you can do
this in the view:
$this->context->getRequest()->setAttribute('populate', new
AgaviParameterHolder(array(
'qstID' => $userDt['qstID'],
'textfieldname' => 'value',
'foo' => 'bar',
)), 'org.agavi.filter.FormPopulationFilter');
that will always run, however, also on POST, which you likely don't
want (there, you want to show the data submitted again, because an
error occured), so you should wrap that line into an if block:
if($this->context->getRequest()->getMethod() == 'read') {
}
Hope that helps,
David
P.S: you really should consider using PDO instead of mysql_*, Agavi
has a driver for PDO, too.
Am 14.03.2007 um 09:19 schrieb surej ns:
> HI David Zülke ,
>
> Just see my code. I have written this code to populate list in a
> select box from DB.
> Here is the code
>
> Template file
> <select name= "qstID" >
> <option value ="0" >Select</option>
> <?
> while( $row =mysql_fetch_array( $template['qstlist' ]) )
> {
> if($userDt ['qstID']== $row['qstID' ]){
> echo"<option value=". $row[ 'qstID']." selected >" .$row
> ['qst']. "</option>";
> }
> else{
> echo"<option value=". $row[ 'qstID'].">" .$row[ 'qst']."</
> option>" ;
> }
> }
> ?>
> </select>
>
> Action file
> public function executeRead(AgaviRequestDataHolder $rd)
> {
> $list = $this->getContext()->getModel( 'GetQstLst', 'Default')-
> >GetQstLst();
>
> $this->setAttribute('list' ,$list );
> }
> View File
> public function executeHtml(AgaviRequestDataHolder $rd)
> {
> parent::setupHtml( $rd);
> $this->setAttribute('qstlist' ,$this ->getAttribute('list'));
>
> }
> Now my issue is..
> I have a select box in which value is generated through DB. When
> the page loads for the first time the select box is filled. When I
> press submit button. The validation occurs and the error message
> comes at top. At this time the select box gets Blank or the list
> gets empty. I have provided validation only to a text box and not
> to this select box.
> How can I retain the value after validation in select box?
>
> Hope u all understand my issue..
>
> Thax
>
> surej
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.agavi.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users