Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:01:30+00:00 2026-06-02T18:01:30+00:00

In my forum when I add a topic, I have a dropdown with all

  • 0

In my forum when I add a topic, I have a dropdown with all possible categories. When I post and one of the text fields is empty there comes an error, and I want to keep the selected item in the dropdown selected.

I did it before but not with Smarty. Can somebody see what I am doing wrong?

$query_cat = "
    SELECT
        fcID
        ,fcName
    FROM
        forum_categories
    ";
    $exec_cat = mysql_query($query_cat);    
    while($categories = mysql_fetch_assoc($exec_cat))
    {
        if(isset($_POST['category']))
        {
            $selected = ' selected';
        }
        else
        {
            $selected = '';
        } 
    }
    $this->view->assign('selected', $selected);

    if ($_SERVER['REQUEST_METHOD'] == 'POST')  
    {  
        $row = mysql_fetch_assoc($exec_cat);
        $subject = mysql_real_escape_string(htmlentities($_POST['subject']));
        $content = mysql_real_escape_string(htmlentities($_POST['content']));

        $query_add_topic = "
        INSERT INTO
            forum_topics
        (
            ftDate
            ,fcID
            ,fuID
            ,ftSubject
            ,ftMessage
        )
        VALUES
        (
            NOW()
            ,'".$_POST['category']."'
            ,'".$_SESSION['userid']."'
            ,'".$subject."'
            ,'".$content."'
        )
        ";
        $exec_add_topic = mysql_query($query_add_topic);
    }
    else
    {
        while ($row = mysql_fetch_assoc($exec_cat))
        {
            $entries[] = $row;
            $this->view->assign('entries', $entries);
        }
    }

And smarty

<table width=100%>
<tr>
    <td>Onderwerp:</td>
</tr>
<tr>
    <td width="50"><input type="text" name="subject"></td>
</tr>
<tr>
    <td>Categorie type</td>
</tr>
<tr>
    <td><select name="category">
    {foreach from=$entries item=entry}
            <option value="{$entry.fcID}"{$selected}>{$entry.fcName}</option>
    {/foreach}
        </select>   
    </td>
</tr>
<tr>
    <td class="text"><textarea name="content" cols="50" rows="10"></textarea></td>
</tr>
<tr>
    <td colspan="2"><input type="submit" name="send" value="Verstuur"></td>
</tr>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:01:32+00:00Added an answer on June 2, 2026 at 6:01 pm

    There is a Smarty tag for creating the <option> tags inside a select, {html_options}. The documentation for it is here. Besides not having to build your own loop in the template, you can also specify the selected value as a parameter, which you can pass in from PHP through your $smarty object. That will let you create a <select> with minimal effort and maximum smarty goodness, easily passing in the previously selected value for your topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a wordpress site and i am trying to add a phpbb3 forum
In my project I have a Forum that has many Topics, and each Topic
I am using the code from http://www.cocos2d-iphone.org/forum/topic/6889 to add a UIView to the screen
I have some xml: <article> <uselesstag></uslesstag> <topic>oil, gas</topic> <body>body text</body> </article> <article> <uselesstag></uslesstag> <topic>food</topic>
How do I add: pl\bin to my VS2008 PATH? I read in a forum
What are some good tutorials on how to add form fields with jquery?
I have used hook_form_FORM_ID_alter( ) function to alter a menu_edit_menu form to add few
How do you add Search form to your Views in Drupal? Do I have
I want to have a Form that can Add or Delete TextFields. I was
In Cocos2d, I have read that [[[[CCDirector sharedDirector] openGLView] window] addSubview:someButton]; will add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.