Skip to content

Instantly share code, notes, and snippets.

@rsanchez
Created November 14, 2011 15:12
Show Gist options
  • Save rsanchez/1364133 to your computer and use it in GitHub Desktop.
Save rsanchez/1364133 to your computer and use it in GitHub Desktop.

Revisions

  1. rsanchez revised this gist Apr 19, 2012. 1 changed file with 2 additions and 11 deletions.
    13 changes: 2 additions & 11 deletions gistfile1.html
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,5 @@

    {/exp:safecracker}

    {!-- add this code if you are using Matrix --}
    <script type="text/javascript">
    $("table.matrix tbody tr :input").each(function() {
    var i = $(this).parents("tr").index();
    if (this.name.match(/row_order/) && this.value.match(/^row_id_\d+$/)) {
    this.value = "row_new_"+i;
    } else {
    this.name = this.name.replace(/row_id_\d+/g, "row_new_"+i);
    }
    });
    </script>
    {!-- add this code if you are using Matrix (w/ PHP on Input) --}
    <?php $_GET['clone'] = 'y' ?>
  2. rsanchez revised this gist Apr 19, 2012. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion gistfile1.html
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,16 @@

    <input type="hidden" name="entry_id" value="">

    {/exp:safecracker}
    {/exp:safecracker}

    {!-- add this code if you are using Matrix --}
    <script type="text/javascript">
    $("table.matrix tbody tr :input").each(function() {
    var i = $(this).parents("tr").index();
    if (this.name.match(/row_order/) && this.value.match(/^row_id_\d+$/)) {
    this.value = "row_new_"+i;
    } else {
    this.name = this.name.replace(/row_id_\d+/g, "row_new_"+i);
    }
    });
    </script>
  3. rsanchez revised this gist Apr 19, 2012. 1 changed file with 0 additions and 13 deletions.
    13 changes: 0 additions & 13 deletions matrix.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    /**
    * if you have a matrix, you'll need to add this after your form
    */
    <script type="text/javascript">
    $("table.matrix tbody tr :input").each(function() {
    var i = $(this).parents("tr").index();
    if (this.name.match(/row_order/) && this.value.match(/^row_id_\d+$/)) {
    this.value = "row_new_"+i;
    } else {
    this.name = this.name.replace(/row_id_\d+/g, "row_new_"+i);
    }
    });
    </script>
  4. rsanchez revised this gist Apr 19, 2012. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions matrix.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    /**
    * if you have a matrix, you'll need to add this after your form
    */
    <script type="text/javascript">
    $("table.matrix tbody tr :input").each(function() {
    var i = $(this).parents("tr").index();
    if (this.name.match(/row_order/) && this.value.match(/^row_id_\d+$/)) {
    this.value = "row_new_"+i;
    } else {
    this.name = this.name.replace(/row_id_\d+/g, "row_new_"+i);
    }
    });
    </script>
  5. rsanchez revised this gist Nov 14, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.html
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    {!--example url: template_group/template/123--}
    {exp:safecracker entry_id="123" return="template_group/template/ENTRY_ID"}
    {exp:safecracker entry_id="{segment_3}" return="template_group/template/ENTRY_ID"}

    ...

  6. rsanchez created this gist Nov 14, 2011.
    15 changes: 15 additions & 0 deletions gistfile1.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {!--example url: template_group/template/123--}
    {exp:safecracker entry_id="123" return="template_group/template/ENTRY_ID"}

    ...

    {!--
    this is the trick that duplicates the entry
    even though entry_id 123 is LOADED into this form
    this blank entry_id field will trick SC into thinking
    this is a new entry
    --}

    <input type="hidden" name="entry_id" value="">

    {/exp:safecracker}