I’m developing an extension that validates my SAEF. For that i’m using the “weblog_standalone_insert_entry” hook, i can check my fields on errors but don’t know what to do when I get an error.
I’m looking for something that stops the extension and return back to the SAEF (with a report of what fields where empty).
I tried the function redirect but that resets all my fields.
Any ideas?
Sorry for resurrecting an old post like this moderators but I am wondering (I think) the same sort of thing.
I too am using the weblog_standalone_insert_entry hook in an extension I am making.
What I am needing to do is if say someone makes a mistake in the SAEF such as trying to create a title that starts with numbers which isn’t allowed then you get the standard error page come up telling you to go back and fix your errors. This is fine but my extension still runs its code. What I want is for the code in the extension not to run unless the form submission is correct.
Having the rest of my extension run when the entry isn’t even going to get saved as it isn’t a correctly formatted entry will cause problems.
Just wondering if I am using the correct hook or is there something else I should be doing to check when the hook is called to see if the entry is actually going into the database or not?
Any help on this would be greatly appreciated.
Best wishes,
Mark
As a quick update to this I tried adding :
print_r($_POST)
to my extension to see exactly what gets passed when submitting an SAEF entry but I don’t see anything in there that would help with this. No entry_id is passed so I can’t check to see if the entry made it successfully to the database or not, can I?
Also there are no error messages or anything like that so all I am getting is the main data such as the title, url_title and all other stuff. I don’t really want to have to place error checking routines in the extension because if I ever add a new field to the SAEF then I would have to place more code into the extension.
There must be something I’m missing aren’t I? I simply want my extension to only run its code if the SAEF form submission is successful and the entry makes it into the database.
Anyone any ideas?
Thanks.
Best wishes,
Mark
Hi Mark, looking at the code in mod.standalone.php lines 97-106, it appears that the actual insertion of data is performed by cp.publish.php, line 3324 onwards. But it doesn’t look as though there’s any flag to suggest that a prospective entry has originated from a SAEF rather than the control panel, though I’ve not looked too deeply into that, so could be wrong. If I’m right, you may need to find a way of adding one first. Then you’d be able to do whatever you need to do by using the submit_new_entry_start, submit_new_entry_end, submit_new_entry_redirect or submit_new_entry_absolute_end hooks. Probably one of the latter two I guess.
Hope that helps.
Hiya,
Thanks for taking a look at that. I thought something like that as the hooks and data that the SAEF gives back to me don’t give me much to go on unfortunately.
I think I kind of found a way to do what I want to do and had to place an if else structure in my extension. All very weird though as the if does what it’s supposed to do but it’s mainly the else I want to fire but it never does! All very very strange.
Best wishes,
Mark
No problem. Nice to be able to help the helper.
and thank you for the help, it’s much appreciated. Always seems to go quiet around here when I ask a question but you have re-affirmed my faith 😊
Sounds like you might have an iffy if 😉
Yep but just can’t see why though. I’ve even hard-coded a definite if else structure that just can never ever be the if part and so the else should run but never does. All very strange!
Look forward to seeing what it is you’re working on.
Nothing too clever, just want to run some code when an SAEF form is submitted but only run the code if there are no errors in the SAEF such as title filled out correctly and all required fields filled in. At the moment the code (if I take out the if else structure) runs fine but also runs if taken to an error page but if I put in the if else structure which is made to catch these situations then it never runs!
Very very weird and I’m sure I’m just missing something obvious somewhere.
Best wishes,
Mark
Sounds as though the code is running either before the error checking/redirect to error page routine… or that it’s running afterwards regardless. So you’d need to either run it before, or make sure that it’s prevented from running after the error checking etc. Difficult to guess without seeing some code. If you like, I may be able to take a look and see if I can spot something that you might have missed. Not guaranteeing that I’ll be able to solve it though. This is all new to me too.
Here’s a thought - have you added $EXT->end_script = TRUE to your code to prevent the hook from being returned to the SAEF file? Otherwise it would be and the weblog data would be inserted anyway.
Hiya,
Thanks for that. Yep I had added in the $EXT->end_script = TRUE part but have never truly understood that or if I’m even using it correctly :-(
I’ve placed the extension code and language code into two pasties and the links are :
For now I have commented out lines 133-143 and 185 is also commented out which is the end bracket for the else shown on line 140. The extension works fine if you leave those lines out and does what it’s supposed to do and would be fine if you used it in an SAEF which has javascript validation on it so that the form can’t even be submitted unless filled in correctly so the error page never shows up but I want to be able to get it working without the need for javascript validation thus why I am checking the title is filled in correctly in the extension file and also then checking that all the required fields are also filled in. If you uncomment the lines I mentioned then you’ll see that it can do the if part of the statement but will never run the else. I’m sure I’m missing something obvious somewhere but if anyone can lend a hand on this then that would be great, thanks.
Oops meant to mention that you will need to first create a custom profile field and place the short name of that field into the extensions settings page once you have installed it. I am going to make the settings into a drop down where you will select the field you wish to use but it is like that for now just so that I can hopefully get it working a little faster.
Thanks again for the help on this it’s much appreciated.
Best wishes,
Mark
Try changing line 72:
global $DB, $FNS, $SESS;
to
global $EXT, $DB, $FNS, $SESS;
as otherwise I don’t think $EXT-end_script will be applied: end_script is a variable of $EXT. No $EXT, no variable.
Also, put the $EXT->end_script = TRUE;
before the return statement line 136, else it won’t be run either (even if you do have $EXT in place).
Might need to add a return on line 184 after the final call to $EXT-end_script too to return context back to the SAEF. Not sure….
Then test it again.
Looking at the hook for this in line 93 of mod.weblog_standalone.php basically all $EXT->end_script does is provide a way to prevent the function from carrying on any further after your extension is run. The hook provides a way of looping out the EE code into that of your extension. Usually the progress of it is out and around your extension and then back to its original context and onwards. With $EXT->end_script in place that’s stopped, and after your extension is run whichever function the hook was in is returned out of, back to the context that it in turn was running in.
Hope that makes sense.
Gonna go and have a look now. Sounds like this may be similar(ish) to something I put together the other day. I’ve got an extension that updates a total on a custom profile field on IPN receipt.
You are very kind, thank you. I swear it must be something silly that I am / or am not doing but for the life of me I can’t see it.
Thanks again for taking a look at this for me, much appreciated.
Best wishes,
Mark
I think I am really missing something now. I have tried with the $EXT->end_script = TRUE; bit in the places you mentioned and I’ve tried it just about everywhere and anywhere in all kinds of flavours but just can’t get any of them to work. Whenever I place that into the extension code when I submit the form the page just goes completely blank, no source code nothing! :-(
Very very weird! I think I’m starting to lose hair over what I think should be fairly simple. It just seems that my if part which is on line 133 will work but never the else just under it which is the main part of the code!! Very weird! I may just try changing the if and else parts around to run my code on the if and then just forget the else or something like that.
If you have any other ideas though then I’m all ears 😊
Thanks again for looking at this for me.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.