Limiting Categories and Channel Entries with Custom Member Field
Posted: 19 November 2010 01:12 AM   [ Ignore ]
Has a Great Personality
Rank
Total Posts:  41
Joined  2010-11-08

Guys, I know this is not a safecracker issue and have posted it on the EE forums with no response so far.  If anything springs to mind I would be very grateful of the assistance.

I have a SAEF to publish match fixtures and I have a couple of selects that I want to limit the categories and channel entries being returned for particular members by using a custom member field.

I have used php to pull the member field

<?php
$league_category 
'{exp:member:custom_profile_data}{league_category}{/exp:member:custom_profile_data}';
?> 

For the categories the php code works fine and I am able to display the categories list that I need.

But to get the channel entries working in the first place I have had to use an embed, and I cannot get the php working to display the teams within the embed.

Main SAEF

{exp:safecracker channel="fixtures" 
    
return="fixtures/thanks_row" 
    
datepicker="no"
}

<fieldset>
<
input type="hidden" name="allow_comments" value="n" />
<
input type="hidden" name="status" value="Pending" />

<?php
$league_category 
'{exp:member:custom_profile_data}{league_category}{/exp:member:custom_profile_data}';
?>

<table cellspacing="0">
    <
tr>
        <
td>
            <
input type="text" name="entry_date" id="entry_date" value="{current_time format='%Y-%m-%d %H:%i'}" maxlength="23" size="16" />
            <
input type="hidden" name="title"  id="title" value="{title}" />
            <
select name="category[]">
                <
option value="" selected="selected">--</option>
               
{exp:channel:categories cache="yes" channel="seasons" refresh="60" style="linear"}
            {if category_id 
== '<?php echo league_category?>' || parent_id == '<?php echo $league_category?>'}
                    {if parent_id
=='0'}<optgroup label="{category_name}">
                    
{if:else}<option value="{category_id}">{category_name}
                    {
/if}
                    {if parent_id
=='0'}</optgroup>
                    
{if:else}</option>
                    
{/if}
            {
/if}
                {
/exp:channel:categories}
            
</select>

        
{embed=fixtures/home_team} {embed=fixtures/away_team}

            
<button type="submit" name="submit">Submit</button>
        </
td>
    </
tr>
    <
tr>
        <
td>
            
        </
td>
    </
tr>
</
table>
</
fieldset>
{/exp:safecracker} 

Embed

<select name="fixture_home_team">
    <
option value="" selected="selected">--</option>
        
{exp:channel:entries channel="teams" dynamic="no" orderby="title" sort="asc" limit="200" category="<?php echo $league_category?>"  disable="pagination|member_data|custom_fields|category_fields"}
            
<option value="{entry_id}">{title}</option>
        
{/exp:channel:entries}
</select
Profile
 
 
Posted: 19 November 2010 01:17 AM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Try adding the same php code for setting the league category inside the embed as well.

<?php
$league_category 
'{exp:member:custom_profile_data}{league_category}{/exp:member:custom_profile_data}';
?> 
<select name="fixture_home_team">
    <
option value="" selected="selected">--</option>
        
{exp:channel:entries channel="teams" dynamic="no" orderby="title" sort="asc" limit="200" category="<?php echo $league_category?>"  disable="pagination|member_data|custom_fields|category_fields"}
            
<option value="{entry_id}">{title}</option>
        
{/exp:channel:entries}
</select
Profile
 
 
Posted: 19 November 2010 01:23 AM   [ Ignore ]   [ # 2 ]
Has a Great Personality
Rank
Total Posts:  41
Joined  2010-11-08

Yeah tried that and have it set to allow php as well.

Profile
 
 
Posted: 19 November 2010 01:27 AM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I see what it is. You can’t have php on input and expect it to parse those EE tags.

Try this

{exp:safecracker channel="fixtures" 
    
return="fixtures/thanks_row" 
    
datepicker="no"
}

<fieldset>
<
input type="hidden" name="allow_comments" value="n" />
<
input type="hidden" name="status" value="Pending" />

<?php
$league_category 
'{exp:member:custom_profile_data}{league_category}{/exp:member:custom_profile_data}';
?>

<table cellspacing="0">
    <
tr>
        <
td>
            <
input type="text" name="entry_date" id="entry_date" value="{current_time format='%Y-%m-%d %H:%i'}" maxlength="23" size="16" />
            <
input type="hidden" name="title"  id="title" value="{title}" />
            <
select name="category[]">
                <
option value="" selected="selected">--</option>
               
{exp:channel:categories cache="yes" channel="seasons" refresh="60" style="linear"}
            {if category_id 
== '<?php echo league_category?>' || parent_id == '<?php echo $league_category?>'}
                    {if parent_id
=='0'}<optgroup label="{category_name}">
                    
{if:else}<option value="{category_id}">{category_name}
                    {
/if}
                    {if parent_id
=='0'}</optgroup>
                    
{if:else}</option>
                    
{/if}
            {
/if}
                {
/exp:channel:categories}
            
</select>
{exp:member:custom_profile_data}
        {embed
="fixtures/home_team" league_category="{league_category}"} {embed="fixtures/away_team" league_category="{league_category}"}
{
/exp:member:custom_profile_data}

            
<button type="submit" name="submit">Submit</button>
        </
td>
    </
tr>
    <
tr>
        <
td>
            
        </
td>
    </
tr>
</
table>
</
fieldset>
{/exp:safecracker} 
<select name="fixture_home_team">
    <
option value="" selected="selected">--</option>
        
{exp:channel:entries channel="teams" dynamic="no" orderby="title" sort="asc" limit="200" category="{embed:league_category}"  disable="pagination|member_data|custom_fields|category_fields"}
            
<option value="{entry_id}">{title}</option>
        
{/exp:channel:entries}
</select
Profile
 
 
Posted: 19 November 2010 01:36 AM   [ Ignore ]   [ # 4 ]
Has a Great Personality
Rank
Total Posts:  41
Joined  2010-11-08

Many thanks That’s it sorted, I have a lot to learn.  Form takes ages to load, probably all the parsing is having to do.

Is it possible to publish several entries using the one form what I am using at the moment has several iframes each one has its own submit.

Profile
 
 
Posted: 19 November 2010 01:40 AM   [ Ignore ]   [ # 5 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Currently there’s no way to edit multiple entries with one form.

Profile
 
 
Posted: 19 November 2010 01:42 AM   [ Ignore ]   [ # 6 ]
Has a Great Personality
Rank
Total Posts:  41
Joined  2010-11-08
Rob Sanchez - 19 November 2010 01:40 AM

Currently there’s no way to edit multiple entries with one form.

Sorry I mean publish new entries.

Profile
 
 
Posted: 19 November 2010 01:42 AM   [ Ignore ]   [ # 7 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Same deal, one entry per form smile

Profile
 
 
Posted: 19 November 2010 01:45 AM   [ Ignore ]   [ # 8 ]
Has a Great Personality
Rank
Total Posts:  41
Joined  2010-11-08

Cheers

I will work away and see how I get one but let me know if/when you guys are free.

Profile