Duplicate textareas and text inputs in SafeCracker form
Posted: 17 January 2011 09:36 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17

Using SafeCracker on EE 2.1.3 and it’s working great, just as expected. One thing that’s weird is that I’m getting two of the same textareas and text inputs in my form. The duplicate is not identical to the first one but it’s pretty similar. Take a look below to see what I mean. I’m using the code that’s provided in the documentation for custom fields so I can’t imagine what’s going on (other fieldtypes, including Matrix, is working fine).

Here’s the code in my form template for textareas and text inputs:

{if textarea} <textarea id="{field_name}" name="{field_name}" dir="{text_direction}" rows="{rows}">{field_data}</textarea{/if} 
        
{if text} 
<input type="text" dir="{text_direction}" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" /> {/if} 

This is what SafeCracker is spitting out:

<textarea rows="6" dir="ltr" name="profile-overview" id="profile-overview">Lorem ipsum dolor</textarea>
<
textarea dir="ltr" id="profile-overview" rows="6" cols="90" name="profile-overview">Lorem ipsum dolor</textarea
<input type="text" size="50" maxlength="128" value="" name="profile-website-url" id="profile-website-url" dir="ltr">
<
input type="text" maxlength="128" dir="ltr" id="profile-website-url" value="" name="profile-website-url"

Does anyone have a solution for this or even an idea of what could be going wrong?

[ Edited: 17 January 2011 09:38 AM by Chris Brauckmuller ]
Profile
 
 
Posted: 17 January 2011 07:53 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Can you post your full template?

Profile
 
 
Posted: 17 January 2011 08:52 PM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17
{exp:safecracker return="/" channel="dining-guide" entry_id="{embed:entry_id}"}

    
<link href="{path=css/_ee_saef_css}" type="text/css" rel="stylesheet" media="screen" />
    
{exp:jquery:script_tag}
    {exp
:jquery:script_tag ui="datepicker"}


    
<label for="title">Business Name</label>
    <
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" />

    <
hr/>
    
    <
input type="hidden" id="status" name="status" value="open" />
    
    
{custom_fields}
    
        
<h2><label for="{field_name}">{if required}{/if}{field_label}</label></h2>
        
        <
class="instructions">{field_instructions}</p>
        
        
{formatting_buttons}
        
        {if error} 
<class="error">{error}</p{/if}
        
        {if textarea} 
<textarea id="{field_name}" name="{field_name}" dir="{text_direction}" rows="{rows}">{field_data}</textarea{/if} 
        
        {if text} 
<input type="text" dir="{text_direction}" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" /> {/if} 
        
        {if select} 
<select id="{field_name}" name="{field_name}"{options}<option value="{option_value}"{selected}>{option_name}</option>{/options} </select{/if} 
        
        {if date} 
<input type="text" id="{field_name}" name="{field_name}" value="{field_data}" size="50" /> {/if} 
        
        {if checkbox} {options}
<label class="checkbox">{option_value} <input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked} /></label>{/options} {/if} 
        
        {if radio} {options}
<label class="checkbox">{option_value}<label class="checkbox"> <input type="radio" id="{field_name}" name="{field_name}" value="{option_value}"{checked} /></label>{/options} {/if} 
        
        {if file} {display_field} {
/if} {if safecracker_file} {display_field} {/if} {if relationship} <select id="{field_name}" name="{field_name}"{options}<option value="{option_value}"{selected}>{option_name}</option>{/options} </select{/if} 
        
        {if multiselect} 
<select id="{field_name}" name="{field_name}[]" multiple="multiple"{options}<option value="{option_value}"{selected}>{option_name}</option>{/options} </select{/if}
        
    
<hr/>
    
    
{/custom_fields}

    
    
    {category_menu}
        
<label for="categories">Categories</label>
        <
select name="category[]" id="categories">
        
{select_options}
        
</select>
    
{/category_menu}
        
    {if captcha}
        
<label for="captcha">Please enter the word you see in the image below:</label
        {captcha}
        
><input type="text" name="captcha" value="{captcha_word}" maxlength="20" />
    
{/if}
    
    
<hr/>

    <
input type="submit" name="submit" value="Submit" />

{/exp:safecracker} 

Thought it might have something to do with the fact that it’s an embedded template but I put it in it’s own template and same thing.

Profile
 
 
Posted: 17 January 2011 09:04 PM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Do you have safecracker_file installed properly? Are you using a safecracker_file field in this channel? Try removing (momentarily) the file and safecracker file conditionals, to see if those are the trouble makers.

Profile
 
 
Posted: 17 January 2011 09:16 PM   [ Ignore ]   [ # 4 ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17

I do not have SafeCracker File installed as a fieldtype.

I removed the SafeCracker File and File conditionals and it fixed my text inputs and textareas, but it broke my Matrix fields (they disappeared altogether).

I tried removing the file and SafeCracker file conditionals independently of one another and removing either one breaks Matrix fields. This doesn’t seem to make any sense because if SafeCracker file wasn’t installed in the first place why would it “enable” my Matrix fields?

Profile
 
 
Posted: 17 January 2011 09:18 PM   [ Ignore ]   [ # 5 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Are you using the normal File field? Basically, you shouldn’t have any conditionals in there that you don’t need. Also, how are you displaying the matrix field? You don’t have a matrix conditional in there?

Profile
 
 
Posted: 17 January 2011 09:21 PM   [ Ignore ]   [ # 6 ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17

I’m not using the normal file field so I got rid of it. But that also broke my Matrix field. Forgive me if this is dumb but I don’t have a Matrix conditional in there, Matrix just sort of showed up on its own once I pasted in your guys’ code. I didn’t see any specific instructions on how to enable Matrix and i just felt like I got lucky haha.

Profile
 
 
Posted: 17 January 2011 09:24 PM   [ Ignore ]   [ # 7 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Here’s what’s happening: as safecracker is looping through your custom_fields loop, it’s registering FALSE positives on the file/safecracker_file conditionals, and therefore rendering the {display_field} tag for each custom field in your channel. This is why you were getting double fields and the matrix field magically showing up. Get rid of any conditionals you don’t need and add one for matrix:

{if matrix}{display_field}{/if} 
Profile
 
 
Posted: 17 January 2011 09:27 PM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17

That did it. Thank you so much for your help. So in the future, anytime I want to enable an additional fieldtype that’s not a native EE fieldtype (e.g. Brandon Kelly’s FF P&T Checkboxes), I’d use that same code but replace “matrix” with whatever the name of the field is in my /system/expressionengine/third_party folder?

Profile
 
 
Posted: 17 January 2011 09:31 PM   [ Ignore ]   [ # 9 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Precisely. So it’d be:

{if pt_checkboxes}{display_field}{/if} 

or

{if pt_checkboxes} {options}<label class="checkbox">{option_value} <input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked} /></label>{/options} {/if} 
Profile
 
 
Posted: 17 January 2011 09:34 PM   [ Ignore ]   [ # 10 ]
Wallflower
Rank
Total Posts:  7
Joined  2011-01-17

Excellent, thank you so much. I’ve been very impressed with how quickly you replied to my post and better yet how quickly you solved it. Cheers to you guys on great customer service!

Profile