Select option values
8 posts by 3 authors in: Forums > CMS Builder
Last Post: January 20, 2012 (RSS)
By nmsinc - January 18, 2012
<?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
Re: [nmsinc] Select option values
By Jason - January 18, 2012
You should be able to simplify this drop down like this:
<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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Select option values
By nmsinc - January 18, 2012
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
Re: [nmsinc] Select option values
By Dave - January 19, 2012
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.
interactivetools.com
Re: [nmsinc] Select option values
By Jason - January 19, 2012
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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Select option values
By nmsinc - January 19, 2012
Not pulling from any other table, simply want to limit selections in pulldown based on user type!
Re: [nmsinc] Select option values
By Jason - January 20, 2012
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:
<?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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/