Help with adding Page Name to form submission

Permalink
I have added some code to "mail > block_form_submission.php" to show which page a form was filled out from.

Page::getCurrentPage()->getCollectionName();


This seemed to work nicely, but......

I have now added JordanLev's Ajax Form block, and now I get an error
<b>Fatal error</b>:  Call to a member function getCollectionName() on a non-object in <b>


Anyone know how I can achieve this using the Ajax block?

PS: I know very little about php so don't know how to get around the "non-object" error

 
JohntheFish replied on at Permalink Reply
JohntheFish
During an ajax submission, the form submit is being handled by the ajax tool, not the page it came from.

Unless the ajax tool recreates the page view, then a current page does not exist.

Here is another way of doing it by adding a field to the form:
http://www.concrete5.org/documentation/how-tos/designers/record-the...
jjcdesign replied on at Permalink Reply
Thanks John,

That's working really nicely, but.... There's always a but

The code example produces the page's number (ID), what would I need to do to get the page's actual name?

Many thanks for your help so far

Kelv
JohntheFish replied on at Permalink Reply
JohntheFish
If you look in the documentation, you can get a page object by its cID, then get the name on that object.

( Or you could use my Magic Data and Magic Data forms )
JohntheFish replied on at Permalink Reply
JohntheFish
jjcdesign replied on at Permalink Reply
Thanks for the input John, but unfortunately, the documentation and terminology tends to go over my head. I was slightly confused by your answer because (as far as I can work out) the solution you gave was Javascript, but to get the page name I would have to use PHP (I may be wrong - I often am! lol). If it does indeed need PHP, where would this go? Would it be more difficult because I'm using the Ajax Form Bock? How do you get the PHP result into Javascript?

Lots of questions for my lack of C5 knowledge.

Anyway, I have managed to get it to work by doing what you said, but by doing it all in a php block. Not sure if its correct, good code practice etc etc, but it's working :)

This is what I did if anyone wants to know (placed into a PHP Block):
$pageFormFilledOut = Page::getCurrentPage()->getCollectionName();
echo '<script>$(document).ready(function(){
  if(CCM_EDIT_MODE && CCM_EDIT_MODE !== false){
    return;
  }
    $(\'#Question43,#Question44,#Question45\').hide();
    $(\'#Question43,#Question44,#Question45\').val("';
echo $pageFormFilledOut;
echo '");
});
</script>';


Many thanks for getting me thinking about it a bit more, but god, does it hurt your head when you don't really understand coding!
hrcv replied on at Permalink Reply
hrcv
Any clue on how to get this done today under V8.4.3