The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Re-filling form fields of populated dropdown
I just did a clean install of 2.0.4. I tried to use the re-filling form fields using the api tutorial but I couldn't get it to work. I discovered replacing @$fields with @$_POST seemed to do the trick.

However, I am now populating the drop-downs with the information in the ft database. It works great and is now very easy to update among all of my forms, but I don't know how to include the refilling form fields script. Can anyone help me with this?

I am using the following code:

$result = @mysql_query("select option_value,option_name from database.ft_field_options where field_group_id='1');
print "<select name='category'>\n";
while ($row = mysql_fetch_assoc($result)){
$value = $row['option_value'];
$name = $row['option_name'];
print "<option value=$value>$name</option>\n";
print "</select>\n";
Hi sogreen,

So just so I understand: the dropdown code that you posted is working okay, you just need it to set the appropriate value in the dropdown?

If that's the case, you're almost done. You'll just need to add something like this:

PHP Code:
= @mysql_query("select option_value,option_name from database.ft_field_options where field_group_id='1');
print "
<select name='category'>\n";
while (
$row = mysql_fetch_assoc($result)){
$value = $row['option_value'];
$name = $row['option_name'];
$selected = ($row['option_value'] == $THEVALUE) ? " selected" : ""; 
  print "
<option value=$value{$selected}>$name</option>\n";
print "

.. and replace "$THEVALUE" with whatever variable contains the value for that field.

Hope this helps a bit. If I misunderstood, post me back.

- Ben
Thank you so much! That did the trick, it works perfectly.
Oops. Upon more testing I have found this isn't working the way I would like...

Now, when you go to the form it automatically selects that last option in each dropdown field. I want it to have the first row (which is a blank field in the database) to show up. Then when the user selects an option, if the recaptcha is entered incorrectly, the option they selected is still selected until they get redirected to the "success" page.

Does this make sense?

Forum Jump:

Users browsing this thread: 1 Guest(s)