1

I have a safecracker form where I need the user to create a new entry. When the form is submitted I want the return address to include the newly created entry id, but I can't figure out how via the documentation.

I have tried:

{exp:safecracker channel="submissions" return="submission-complete/ENTRY_ID" include_jquery="no" safecracker_head="no"}

And:

{exp:safecracker channel="submissions" return="submission-complete/{entry_id}" include_jquery="no" safecracker_head="no"}

Anyone know how to do this?

    $('form#publishForm').ajaxForm({
        dataType: 'json',
        beforeSend: function() {
            status.empty();
            var percentVal = '0%';
            bar.width(percentVal)
            percent.html(percentVal);
        },
        uploadProgress: function(event, position, total, percentComplete) {
            var percentVal = percentComplete + '%';
            bar.width(percentVal)
            percent.html(percentVal);
        },
        success: function(data) {
            var percentVal = '100%';
            bar.width(percentVal)
            percent.html(percentVal);
window.location.href = "/submission-complete/"+data.entry_id;
        }
    });
7
  • You first approach would work as ENTRY_ID and URL_TITLE constants can be used. So Safecraker would redirect to page yoursiteurl.com/submission-complete/xxx. If not could you clarify more this question. May 23 '13 at 13:32
  • Hi @BhashkarYadav. I have suddenly realised that this might be because I am redirecting with ajax. On page load I am finding the return hidden field, taking the address and then in the 'complete' call redirecting to it.
    – ccdavies
    May 23 '13 at 13:53
  • see my edit in your code. The data should be passed within complete function like complete: function(data) . try it. it would help. Also can you see the error console in case of JavaScript error. May 23 '13 at 15:12
  • @BhashkarYadav No errors in error console, but the entry id is returning as 'undefined'.
    – ccdavies
    May 23 '13 at 15:14
  • Can you alert data like: alert (data); and share what JSON you are getting. if its alerting undefined use my updated code. Seems complete function return an object.... May 23 '13 at 15:19
2

As you mentioned within you comment that you are submitting the Safecraker form with AJAX. The Ajax submission returns JSON data which have entry id also. So you can redirect with JavaScript with success function like:

window.location = "/submission-complete/"+data.entry_id;

Take a reference from here: http://ellislab.com/expressionengine/user-guide/modules/safecracker/examples.html#ajax-driven-entry-form

2
  • Ah thanks. Not sure why, but now its not redirecting at all. Can you take a look at my code. I have added it to the question body.
    – ccdavies
    May 23 '13 at 14:55
  • Thanks for the update. Its now returning 'undefined' for the entry id though... any ideas?
    – ccdavies
    May 23 '13 at 15:12
0

I don't think you can since the entry ID won't be created until AFTER the form is submitted.

What you might be able to do is return to the latest entry from the logged in user, will should be the entry they just submitted via Safecracker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.