Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Select option values

 

 


nmsinc
User

Jan 18, 2012, 6:23 AM

Post #1 of 8 (357 views)
Shortcut
Select option values Can't Post

I'm making changes to a section field to limit the options in a drop down to 'admin' or non 'admin' and I' attempting to do so as below with no luck. Any suggestions?

<?php if ($CURRENT_USER['isAdmin']):?>
<select name="company_type">
<option value="Insurance">Insurance</option>
<option value="Independent">Independent</option>
</select>
<?php else: ?>
<select name="company_type">
<option value="Insurance">Insurance</option>
</select>

<?php endif ?>

Thanks - nmsinc


Jason
Staff / Moderator


Jan 18, 2012, 11:04 AM

Post #2 of 8 (352 views)
Shortcut
Re: [nmsinc] Select option values [In reply to] Can't Post

Hi,

You should be able to simplify this drop down like this:


Code
<select name="company_type"> 
<option value="Insurance">Insurance</option>

<?php if ($CURRENT_USER['isAdmin']):?>
<option value="Independent">Independent</option>
<?php endif ?>

</select>


Give this a try and let me know if you run into any problems.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


nmsinc
User

Jan 18, 2012, 11:56 AM

Post #3 of 8 (351 views)
Shortcut
Re: [Jason] Select option values [In reply to] Can't Post

Hi Jason

Thanks for the reply, I used your suggestion and now I receive the following when I attempt to open the section:There was an error creating the list field ''.MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<select name="company_type"> <option value="Insurance">Insurance</option><o' at line 1


Dave
Staff / Moderator


Jan 19, 2012, 7:40 AM

Post #4 of 8 (344 views)
Shortcut
Re: [nmsinc] Select option values [In reply to] Can't Post

Hi nmsinc,

Just to confirm, is this code in the: Admin > Section Editors > Field Editor? And the pulldown is being displayed in the CMS, is that right?

Let me know and I'll try to help.

Dave Edis - Senior Developer
interactivetools.com
 


nmsinc
User

Jan 19, 2012, 8:27 AM

Post #5 of 8 (342 views)
Shortcut
Re: [Dave] Select option values [In reply to] Can't Post

That's correct!


Jason
Staff / Moderator


Jan 19, 2012, 10:57 AM

Post #6 of 8 (333 views)
Shortcut
Re: [nmsinc] Select option values [In reply to] Can't Post

Hi,

In the MySQL query box in the field editor, you can't put in any HTML, only PHP and SQL.

Are you pulling the values for Insurance and Independent from a different table? Could you post the details of that table?

Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


nmsinc
User

Jan 19, 2012, 11:23 AM

Post #7 of 8 (332 views)
Shortcut
Re: [Jason] Select option values [In reply to] Can't Post

Hi Jason,

Not pulling from any other table, simply want to limit selections in pulldown based on user type!


Jason
Staff / Moderator


Jan 20, 2012, 10:32 AM

Post #8 of 8 (318 views)
Shortcut
Re: [nmsinc] Select option values [In reply to] Can't Post

Hi,

The best way to go about doing this would be to create a multi-record section to store your company type values in. You can then pull them in through SQL and create your WHERE clause depending on if the current user is an admin or not.

For example:


Code
<?php $where = ""; ?> 
<?php if (!$CURRENT_USER['isAdmin']) { $where = " WHERE title = 'Independent'"; } ?>

SELECT title, title
FROM `<?php echo $TABLE_PREFIX ?>company_types`
<?php echo $where; ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/