Issue with having multiple safe cracker forms on the same page
Posted: 07 December 2010 12:43 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  5
Joined  2010-11-09

I’ve got a page (a single entry page) where I show the details of an entry, just below that I allow the user to edit the info using safe cracker.  That all works like a charm but (always a but!) over on the right I have a “new entry” form also using safe cracker that is auto-filling with the info displayed on the page.  It’s like it’s relating to the current entry when I want it to be blank and accept a new entry and have nothing to do with the current entry/page info.

Attached you’ll see a screenshot of the page I’m referring to.  The red box comes from this code:

{exp:safecracker channel="tickets" return="intranet/ticket/URL_TITLE" url_title="{segment_3}"}

    Update this ticket
:   &nbsp

    <
input type="hidden" name="title" id="title" value="{title}" size="50" maxlength="100">

    <
input type="hidden" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50" /> 

    <
input type="hidden" name="tickets_issue" id="tickets_issue" value="{tickets_issue}" />

    <
input type="hidden" name="allow_comments" value="y" {allow_comments} />

    <
label for="tickets_status">Urgency</label>
    <
select name="tickets_status" id="tickets_status">
    
{options:tickets_status}
        
<option value="{option_value}"{selected}>{option_name}</option>
    
{/options:tickets_status}
    
</select>

    &
nbsp; &nbsp

    <
label for="tickets_urgency">Urgency</label>
    <
select name="tickets_urgency" id="tickets_urgency">
    
{options:tickets_urgency}
        
<option value="{option_value}"{selected}>{option_name}</option>
    
{/options:tickets_urgency}
    
</select>

    &
nbsp; &nbsp

    <
input type="submit" name="submit" value="Update Ticket" />

{/exp:safecracker} 

and the blue box is from this code:

{exp:safecracker channel="tickets" return="intranet/helpdesk"}

    
<p>
        <
span style="color:red;">*</span> <strong>Your Issue</strong><br />
        <
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100">
    </
p>
    
    <
p>
        <
span style="color:red;">*</span> <strong>The Details</strong><br />
        <
span style="color:#666666; font-size:12px; line-height: .25em;">
            
Explain your issue in as much detail as possibleThe more details you can supply us with the less pesky questions we'll be asking you.
        </span>
        <textarea id="tickets_issue" name="tickets_issue" dir="{text_direction}" cols="38" rows="8">{tickets_issue}</textarea>
    </p>
    
    <p>
        <span style="color:red;">*</span> <strong>Urgency</strong><br />
        <span style="color:#666666; font-size:12px; line-height: .25em;">
        Please use discretion when choosing the urgency. I mean, is it really a critical issue if you can'
t get on Facebook? ;-)
        </
span>
        <
select name="tickets_urgency" id="tickets_urgency">
            
{options:tickets_urgency}
                
<option value="{option_value}"{selected}>{option_name}</option>
            
{/options:tickets_urgency}
        
</select>
    </
p>


    <
input type="hidden" name="tickets_status" id="tickets_status" value="Open" maxlength="75" />
    <
input type="hidden" name="allow_comments" value="y" />
    <
input type="submit" name="submit" value="Submit Ticket" />

{/exp:safecracker} 

It was suggested that the forms are nested so I double checked and they are not.  Any thoughts?  Did I miss something painfully obvious?

Profile
 
 
Posted: 07 December 2010 01:00 AM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Can you try this solution and see if that fixes it and/or causes any problems itself? Open up /system/expressionengine/third_party/safecracker/libraries/safecracker_lib.php around line 84

A few lines into the entry_form function you’ll see this:

$this->initialize(); 

Change it to:

$this->initialize(TRUE); 
Profile
 
 
Posted: 07 December 2010 01:40 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-11-09

From all initial tests it seems to solve it, Rob. smile  Thanks!

Profile
 
 
Posted: 07 December 2010 01:50 AM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

BTW a few more notes:

{text_direction} only works within a custom_fields loop.
You don’t need all those hidden fields in your edit form, they’ll get preserved automatically if they’re not present in the form.

Profile
 
 
Posted: 07 December 2010 02:29 AM   [ Ignore ]   [ # 4 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-11-09

Great to know, thanks!  Seems you are right on all but one of the hidden fields (but it could be something I (un)set or did(nt) do).  If I remove the

<input type="hidden" name="allow_comments" value="y" /> 

line, it will turn off commenting after each edit.  I’m just leaving it in there since it seems to work fine with it.

Profile