PDA

View Full Version : Using <select> dropdown in form - plugin - write to database


wpeloquin
01-31-2011, 10:50 PM
I am having difficulty getting this to work.

In the plugin, i have the following code:


$rkc_getchar['name'] = htmlspecialchars($rkc_getchar['name']);
$rkc_getchar['class_1'] = htmlspecialchars($rkc_getchar['class_1']);
$rkc_getchar['class_1_level'] = htmlspecialchars($rkc_getchar['class_1_level']);

...

'set_name' => TYPE_STR,
'set_class1' => TYPE_STR,
'set_class1_level' => TYPE_UINT,


now, if i use textbox inputs like the following in my template, then it will update the database, and can be recalled properly (example= misc.php?do=plugin&id=1)
<input type="text" name="set_name" id="set_name" value="{vb:raw rkc_getchar.name}" class="primary textbox" style="width:75%" />

however, if i try to use a dropdown selection like the following code, the data does not get saved to the database.

<select name="set_class1_level" id="set_class1_level" value="{vb:raw rkc_getchar.class_1_level}" class="primary" style="width:35%">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


How would i fix this so that a dropdown can be used to limit the choices as needed, instead of having to use an open ended textbox where they could put values outside the proper range?

This seems like it should be an easy fix, and it could just be me staring at code for too long, but i cannot seem to get this to work. Any help would be appreciated.




EDIT: FEB 01, 2011:

OK, it seems that the <select> form IS properly saving to the database, it just does not show up properly when editing. Example, you add an item using the form, and use the name textbox to input "Jimmy", and the <select> to choose number "5", the fields store properly. However, when you go back in to edit that item, it will display "Jimmy" in the text field properly, but the <select> will just show its default value instead of being on "5".

How do I fix that? My workaround at this point is adding
Current Level: {vb:raw rkc_getchar.class_1_level}in front of the <select>, and adding <option value="">Choose Level</option> to the select choices as the default. The problem is that the <select> has to be used every time, even when the user does not wish to update that part of the object, or else the value wipes.

wpeloquin
02-03-2011, 06:51 PM
I have solved this. Put the <option> in a loop in the plugin and called it.