|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Aristotle Smarty Rookie
Joined: 10 Oct 2003 Posts: 8 Location: Phoenix, AZ
|
Posted: Fri Oct 10, 2003 4:30 am Post subject: Using html_options and section |
|
|
I'm trying to use html options and section to allow users to edit an article that they post (like in a CMS). The articles are organized into categories, and I want the category they article in to be auto-selected when the user tries to edit it.
Code: |
{section name="j" loop=$news}
<form action="post.php?mode=news" method="post">
<table>
<tr>
<td>Category:&&</td>
<td><select name="cat">{html_options values=$cat_ids output=$cat_names selected=$news[j].cat_id}</select><br /></td>
</tr>
<tr>
<td>Title:&&</td>
<td><input type="text" name="title" value="{$news[j].title}" /><br /></td>
</tr>
<tr>
<td valign="top">Short Description:&&</td>
<td><textarea rows="7" cols="30" name="description">{$news[j].description}</textarea><br /></td>
</tr>
<tr>
<td valign="top">Message:&&</td>
<td><textarea rows="7" cols="30" name="text">{$news[j].text}</textarea><br /></td>
</tr>
<tr>
<td>&&</td>
<td><input type="hidden" name="id" value="{$news[j].id}" /><input type="submit" name="submit" value="Post!" /><br /></td>
</tr>
</table>
</form>
{/section}
|
Above is the Smarty template code for the section that displays the article edit form. The html_options function is generating a category list, with the category names as the output and the category ids as the values. The section loop is filling the form with the data from the article that is being edited. I can't figure out why the "selected" attribute of html_options is not working; the only reason I can see is that the variable that controlls it is coming from the {section}. I am quite sure that this should work because I have seen it in an O'Reilly tutorial.
Help! _________________ Aristotle |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Oct 10, 2003 5:13 am Post subject: |
|
|
Is the generated HTML correct? Perhaps this thread is related? |
|
Back to top |
|
Aristotle Smarty Rookie
Joined: 10 Oct 2003 Posts: 8 Location: Phoenix, AZ
|
Posted: Fri Oct 10, 2003 10:56 pm Post subject: |
|
|
I get the same result in both Mozilla and IE. Here's the HTML generated by Smarty:
Code: |
<select name="cat"><option label="General" value="1">General</option>
<option label="News and Announcements" value="2">News and Announcements</option>
<option label="Stories" value="3">Stories</option>
<option label="Weblog" value="4">Weblog</option>
</select>
|
Obviously, though the "News and Announcements" category should be selected, Smarty is not even printing the 'selected="selected"' bit. I think this has something to do with the fact that I am using an array variable from the {section} funtion instead of a regular string, but it should still work. _________________ Aristotle |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Oct 10, 2003 11:12 pm Post subject: |
|
|
It seems to all come down to the value of $news[j].cat_id. |
|
Back to top |
|
Aristotle Smarty Rookie
Joined: 10 Oct 2003 Posts: 8 Location: Phoenix, AZ
|
Posted: Sat Oct 11, 2003 5:05 am Post subject: |
|
|
Yay! It works now! There was an inconsistency in one of my functions that was causing "cat_id" to not be assigned. Thanks! _________________ Aristotle |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|