MyBB Community Forums

Full Version: PHP in templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
ok, I have some drop down select boxes, but I want the one initially selected to be the one the users chose last. For example if the choose "username" and press submit its put "1" in the setting1 column of the user table

BUT

I want to be able to make the number in the db the initially selected one, like this:
<select name="setting1" id="setting1">
  <option value="1" <?php if (!(strcmp(1, "{$mybb->user[\'userbarimage\']}"))) {echo "selected=\"selected\"";} ?>>Username</option>
  <option value="2" <?php if (!(strcmp(2, "{$mybb->user[\'userbarimage\']}"))) {echo "selected=\"selected\"";} ?>>Posts</option>
  <option value="3" <?php if (!(strcmp(3, "{$mybb->user[\'userbarimage\']}"))) {echo "selected=\"selected\"";} ?>>Usergroup</option>
  </select>

BUT php cant be used in templates D:
I dont want to force my users to install another plugin :/

I want a workaround for this, any ideas anyone?
Use a variable, for example {$selected1} for option 1, {$selected2} for option 2 and {$selected3} for option 3.

Do:
$selected1 = $selected2 = $selected3 = "";

if (!(strcmp(1, "{$mybb->user[userbarimage]}")))
	$selected1 = "selected=\"selected\"";
elseif (!(strcmp(2, "{$mybb->user[userbarimage]}")))
	$selected2 = "selected=\"selected\"";
elseif (!(strcmp(3, "{$mybb->user[userbarimage]}")))
	$selected3 = "selected=\"selected\"";

// eval part

And in your templates use:
<select name="setting1" id="setting1">
  <option value="1" {$selected1}>Username</option>
  <option value="2" {$selected2}>Posts</option>
  <option value="3" {$selected3}>Usergroup</option>
 </select> 
$selected1 = $selected2 = $selected3 = "";

if (!(strcmp(1, "{$mybb->user[userbarimage]}")))
	$selected1 = "selected=\"selected\"";
elseif (!(strcmp(2, "{$mybb->user[userbarimage]}")))
	$selected2 = "selected=\"selected\"";
elseif (!(strcmp(3, "{$mybb->user[userbarimage]}")))
	$selected3 = "selected=\"selected\"";

// eval part

Should $mybb->user[userbarimage] be $mybb->user['userbarimage']

??? Smile
"{$mybb->user[userbarimage]}" should be $mybb->user['userbarimage']
I just copied your code without actually checking it
lol, thanks Smile I figured that out now XD