admin-page-framework icon indicating copy to clipboard operation
admin-page-framework copied to clipboard

Frontend Visitor Input Fields

Open VR51 opened this issue 8 years ago • 6 comments

Can this be used to add frontend forms that are safe for anonymous user input?

I'm in the middle of converting my own plugins to use Admin Page Framework. Would keep the code lighter if I can use the fields on the frontend too.

VR51 avatar Nov 15 '16 22:11 VR51

Hi,

It's not supported at the moment, sorry. However, it sounds like a good idea.

michaeluno avatar Nov 16 '16 03:11 michaeluno

Thank you, Michael. Would love to see it added.

VR51 avatar Nov 16 '16 15:11 VR51

I've dome some experimentation with front-end forms, using the APF form class. It came out to be functional. One thing to keep in mind is that you have to style the form by yourself.

If you like, you should try this demonstration plugin. Please make sure you have Admin Page Framework v3.8.11 or above.

apf-frontend

The demo plugin consists of four files.

  • admin-page-framework-frontend-form-beta.php - the plugin bootstrap file.
  • AdminPageFramework_FormBeta_frontend.php - an extended form class. (you don't have to pay too much attention to this one.)
  • AdminPageFramework_FrontendFormBeta_Base.php - a base class that provides methods to set up front-end forms.
  • AdminPageFramework_FrontendFormBeta.php - a class which extends the above base class and do necessary set-ups for the form.

For the usage, please see the doc-block section of the AdminPageFramework_FrontendFormBeta_Base class. Basically, you set up a custom hook and define fields and a stylesheet in an extended class. And then just instantiate the extended class. The demo plugin uses the the_content filter hook as an example. You can set your custom filter/action in your desired location. It should be strait forward. Modify the AdminPageFramework_FrontendFormBeta class and play around with it. It might be easier than writing one from scratch.

Hope you like it. Let me know if you encounter problems.

michaeluno avatar Nov 24 '16 23:11 michaeluno

Wow! Thank you very much. Will download and play with this in a few minutes.

VR51 avatar Nov 28 '16 08:11 VR51

  • Nice work, have you added Frontend_Base to the core or I'll have to use it as an add-on?
  • Where it would store the submission data?

shahbaz-dev1 avatar Jun 24 '17 00:06 shahbaz-dev1

@wowthemes It's not part of the core. You have to implement it by yourself. It's just a matter of copy & paste and renaming classes though.

The submission data is not stored anywhere by itself. You want to do it by yourself in the validate() method. Just do something like update_option( $first_parameter, 'your_option_key' ) where $first_parameter is the first parameter variable of the validate() method.

michaeluno avatar Jun 24 '17 06:06 michaeluno