ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker not working

October 25, 2011 9:18am

Subscribe [2]
  • #1 / Oct 25, 2011 9:18am

    Mark Terpstra

    205 posts

    Can you spot any issues with my code below. I can’t get a very simple Safecracker form to submit.

    * Running EE 2.3.1 and Safecracker 2.1
    * Working locally on PHP Version 5.2.13

    When I click Submit, the screen just refreshes and shows the form. No Errors are shown.

    * I double checked the channel name and field names
    * I tried turning on inline errors but that didn’t help
    * I tried turning safecrack_head, json and jquery parameters to yes
    * I tried removing the two custom fields from the form
    * I am loading my own jquery script (which has been removed from this post - but I did verify with Firebug that it’s loading)

    I must be missing something so could you take a look and let me know what I should do to debug this.

    Below is my complete template…

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     [removed][removed]
    </head>
       
    <body>
      
     {if segment_2 == "new"}
      
      Question # {segment_3} has been submitted.
      
     {/if}
      
     {if segment_2 == ""}
     
      Member Group = {logged_in_group_id}
      
      {exp:safecracker channel="questions" return="test/new/ENTRY_ID" safecracker_head="no" json="no" include_jquery="no" datepicker="no"}   
          
       <input type="hidden" name="title" id="title" value="Question Test"/>
       <input type="hidden" name="url_title" id="url_title" value="question-test"/>
       <input type="hidden" name="question_asker" id="question_asker" value="{logged_in_screen_name}" />
       <textarea name="question_text" id="question_text"></textarea>
       
       <button name="submit" type="submit">Submit</button>
      
      {/exp:safecracker}
      
     {/if}
     
    </body>
    </html>

    And below is the output of the above template…

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     [removed][removed]
    </head>
       
    <body>
      
    Member Group = 1
      
    <form id="publishForm" method="post" action="http://www.example.local/test"  enctype="multipart/form-data" >
     
     <div class='hiddenFields'>
      <input type="hidden" name="ACT" value="82" />
      <input type="hidden" name="RET" value="http://www.example.local/test" />
      <input type="hidden" name="URI" value="test" />
      <input type="hidden" name="XID" value="c0a4ef43804d7343d4b47b6a70ddbcff40492389" />
      <input type="hidden" name="return_url" value="test/new/ENTRY_ID" />
      <input type="hidden" name="author_id" value="1" />
      <input type="hidden" name="channel_id" value="7" />
      <input type="hidden" name="entry_id" value="0" />
      <input type="hidden" name="site_id" value="1" />
      <input type="hidden" name="return" value="test/new/ENTRY_ID" />
      <input type="hidden" name="allow_comments" value="n" />
     </div>
       
     <input type="hidden" name="title" id="title" value="Question-1-1319547871"/>
     <input type="hidden" name="url_title" id="url_title" value="question-1-1319547871"/>
     <input type="hidden" name="question_asker" id="question_asker" value="Cull Superadmin" />
     <textarea name="question_text" id="question_text"></textarea>
     
     <button name="submit" type="submit">Submit</button>
    
    </form>
     
    </body>
    </html>

     

  • #2 / Oct 25, 2011 9:56am

    Mark Terpstra

    205 posts

    Nevermind. I figured out that it was this htaccess rule that was causing the problem. I removed it and Safecracker submitted just fine.

    # Add a trailing slash to paths without an extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule ^(.*)$ $1/ [L,R=301]

    Grrrr.

  • #3 / Oct 25, 2011 10:02am

    Mark Terpstra

    205 posts

    I am going to post a fix for this… don’t close the thread quite yet.

  • #4 / Oct 25, 2011 10:26am

    Mark Terpstra

    205 posts

    Here is a hack to get Safecracker working with the htaccess rule above. This hack is not recommended and not supported - but it worked on my end.

    1. Open this file: /expressionengine/modules/channel/mod.channel_standalone.php

    2. Find this snippet on line 992

    $data = array(
          'hidden_fields' => $hidden_fields,
          'action'  => $RET,
          'id'   => 'publishForm',
          'class'   => $this->EE->TMPL->form_class,
          'enctype'   => 'multi'
          );


    3. Add this snippet to line 991 (before the above snippet)

    $RET = $this->EE->functions->remove_double_slashes($RET.'/'); //#quick hack to get Safecracker to work with an htaccess rule that adds a trailing slash

     

  • #5 / Oct 25, 2011 4:26pm

    Sue Crocker

    26054 posts

    Hi, Mark. Thanks for posting your workaround. Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases