Exclude options in category drop down in form

14 posts by 2 authors in: Forums > CMS Builder
Last Post: July 30, 2014   (RSS)

By design9 - July 29, 2014

I am using the upload form and have a drop down that is pulling the options through the "get options from database". It is pulling from the category menu section I built. The issue I am having is that I need to exclude some of the options in the form only. I have a pending (hidden) field in the category menu section but the drown is being pulled from the directory listings table so that drop down still shows all options. My question is there a way to exclude some options from the drop down list that shows on the form?

Thanks!

April

Attachments:

freeform1.php 22K

By claire - July 29, 2014

Hey there

Yes, you can do this, but you'll need to make some changes to the Get Options From Database setting in order to exclude the hidden ones.

Use the Get Options from MySQL Query (Advanced). Look at the following default query:

SELECT fieldname1, fieldname2
FROM `<?php echo $TABLE_PREFIX ?>tableName`

Fieldname1 = the field you had selected for option values

Fieldname2 = the field you had selected for option labels

TableName = the name of the table for this section

Once you've got those in, change it like so:

SELECT fieldname1, fieldname2
FROM `<?php echo $TABLE_PREFIX ?>tableName` WHERE hidden = 0

I can't tell if it's pending or hidden that's the name of the field, but hopefully you get the idea. Any records that are marked as hidden or pending will be excluded.

Let me know if this helps!

--------------------

Claire Ryan
interactivetools.com

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

By claire - July 30, 2014

Yes of course. It's a straightforward SQL statement so you can just add this to it:

ORDER BY dragSortOrder

--------------------

Claire Ryan
interactivetools.com

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

By design9 - July 30, 2014

Like this:

Feel like I am missing some syntax

SELECT fieldname1, fieldname2
FROM `<?php echo $TABLE_PREFIX ?>tableName` WHERE hidden = 0 ORDER BY dragSortOrder

By claire - July 30, 2014

Nope, looks good to me. Just make sure you change the fieldnames/tablename.

--------------------

Claire Ryan
interactivetools.com

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

By design9 - July 30, 2014

Claire,

I just noticed something. Need your help. This option works great but it is effecting the drop down in the CMS backend as well as on the form because of the advanced coding. I only want the excluded options to show on the form not in the backend. Can I just include some code on the actual form page to exclude options in the list only for form page and not in backend?

By claire - July 30, 2014

Ah I see, I thought you meant the CMS form, not a front end form.

You can use something similar on the front end to make this work as well. Can you show me the code you're using to get the options for the front end dropdown?

--------------------

Claire Ryan
interactivetools.com

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

By design9 - July 30, 2014

Sure :

<select name="category">
<option value = "">-Select-</option>
<?php foreach (getListOptions($tableName, 'category') as $value => $label): ?>
<option value = "<?php echo htmlspecialchars($value);?>" <?php selectedIf($value, @$_REQUEST['category']);?>> <?php echo htmlspecialchars($label);?> </option>
<?php endforeach ?>
</select>

By claire - July 30, 2014

You'll have to change this. You can't use getListOptions with a custom WHERE clause. What's the name and structure of the table where you're storing the categories?

--------------------

Claire Ryan
interactivetools.com

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