I’m adding an entry to the database with a custom script of mine (I’m not using Safecracker because I need more control over the form inputs than that add-on allows me). The script is run through EE’s templating engine and uses Active Record syntax.
The relevant piece of the form that adds the new entry is:
<form action="{path='scripts/php_entry_add'}" method="post">The scripts/php_entry_add template generates a URL for the new entry and adds it to the DB. At the end of this template is a standard EE redirect, with the new entry’s URL inserted via PHP:
echo "{redirect='entry/$entry_url/edited'}"In the return template (entry/index) I have the following:
{exp:channel:entries channel="entry" require_entry="yes" url_title="{segment_2}"}
{if segment_3 == 'edited'}Your new entry was added!{/if}
{title}
... other stuff ...
{if no_results}Sorry, no results{/if}
{/exp:channel:entries}On form submit, I get redirected to the correct URL (e.g., http://mysite.com/entry/my-new-entry/edited), but the page is blank, with only the “Sorry, no results” text showing. In other words, the entry can’t be found.
The strangest part is that simply refreshing the page pulls the entry up.
I can verify that the scripts/php_entry_add template works perfectly, and that there is no issue adding the entry to the database. The problem occurs when redirecting to the newly created entry. It’s as though EE hasn’t yet registered that the entry is there. Refreshing the “entry not found” page pulls up the entry, every time.
I suppose the shortest version of my question is: is there some kind of delay between adding entries to a DB and them being available? I can’t think of a reason why the entry would come up as missing, then show up with a simple page refresh. (Well, there’s always the “user error” possibility… 😉) Any ideas?