Possible to Have Form Block Name Default to Page Name where it resides?

Permalink
Thought I had this accomplished, but found out I did not.

Need to add the form block to a Product Default Page Type and have it named the product page when generating product detail pages. So if the page is let's say "P1000" (after the product name) the form block will be named "P1000", and "P1001" and so on. This is to identify the product being inquired about versus the user making a product name entry.

Any ideas appreciated. Thanks!

MrGrowBizz
 
jordanlev replied on at Permalink Reply
jordanlev
It's a bit tricky. You might need to create a custom form block for this purpose (if you're a programmer, I have some boilerplate code that will be helpful for this here:https://github.com/jordanlev/c5_custom_contact_form... ).

If you want to use the built-in form block, though, I think you'd have to create the form in page defaults with a normal text field for the product name, then create a custom template for it and the custom template would parse out that individual question and instead of outputting a textfield it would output a hidden field and set its value to the current page's name. Or you could use jQuery to do this (will be easier to code, but of course will only work if someone has Javascript enabled). But this is a "brittle" solution because editing the form block might change the field name and you'd then need to update your custom code again to match the new name.

If none of this makes any sense to you, then I think unfortunately it's not going to be possible to do this yourself without bringing in some programming help.

-Jordan
MrGrowBizz replied on at Permalink Reply
MrGrowBizz
jordanlev, Thanks much for your great help, will try your possible solutions. Not a programmer, but have grown more comfortable in editing and moving code around. Now wondering if I may be taking the long way around, possibly it would be a shorter route to have the page name pulled directly into the email versus having it derived from the form name? Really appreciate your time in lending a hand! Tim
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Hey, that's a great idea -- much easier than the solutions I proposed. I think if you copy SITEROOT/concrete/mail/block_form_submission.php to SITEROOT/mail/block_form_submission.php, then edit the new copy and replace this line:
$body = t("

...with this:
$body = Page::getCurrentPage()->getCollectionName() . t("

that might do the trick.
MrGrowBizz replied on at Permalink Reply 1 Attachment
MrGrowBizz
Jordan, Fantastic! I will try this once I get my site up and running. I carelessly destroyed some code in my root/config/site.php file trying to add some forum code and now in the process of downloading a backup php file. Trying to remain cool and level headed as I have got a ridiculous amount of weeks in building this site. Attached are the errors if you have any interest in commenting. After adding the code, and removing only what was added this is what I got. Trying to play around with it I accidentally destroyed the key. Stupid me for not coping the file in the first place, thought there was a copy in the core. What an Idiot of a hack I am. Much thanks for your fix on the issue, it will be a tremendous help to me! Tim
MrGrowBizz replied on at Permalink Reply
MrGrowBizz
Well got this fixed! Now for your suggestion Jordan on the real issue!
MrGrowBizz replied on at Permalink Reply
MrGrowBizz
Yabba-Dabba-Doo! Jordan, Works like a charm! A REALLY BIG THANKS! Tim
jordanlev replied on at Permalink Reply
jordanlev
Awesome -- glad you got it figured out!
olay replied on at Permalink Reply
olay
Thanks both … really good solution to exact same problem.