Wordpress Admin/Plugin Form Submit Conventions - wordpress

I have created a plugin, its adds an admin menu page for the menu. The page contains a form.
What I want to know is what is the suggested convention/method of handling form submissions.
Should I load the page and in that check for the $_POST ?
Should I load a separate form page ?
Thanks.
DETAILS:
The thought behind is:
I would want to load a new page and have my submit code it in, but would want to follow convention and the login/rules of capabilities.
(moved into wordpress.stackexchange.com)

You can use a form page into your plugin and when you load the page you check the $_POST like this
//At the page load
if( isset( $_POST["MyForm"]))
{
action();
}
//The Form
<form name="MyForm" method="POST" action="">
</form>
To load the new page if you have submit you have 2 solutions, in the "action()" you generate another page via PHP or you redirect to the other page you want but you have to register it to Wordpress unless you'll have an access denied.
Personnaly i suggest to generate your page into your plugin.

Related

SilverStripe Ajax and Page Controllers

I have a very short question regarding Silverstripe. I have not found a solution anyway on the internet or here. I currently have a form on SS4 that when submit it will run an AJax request and render new content (page). The problem I have is that the content does not display and it seems to be related to the fact that the content that is rendered in is managed by a different Page controller. So it could not find the content when rendering through Ajax from another page. How would I resolve this without refreshing the page ?
Thanks in advance !
you would submit to the same page, which has a function to generate/return the new page. note that when submitting via ajax you need to include the FormAction button in the submitted fields.

jQuery mobile pages not loading correctly after servlet redirect

I have some pages in my mobile web app based on jQuery Mobile that need to be accessible without authentication and some only after user has been authenticated. My solution is based on this tutorial: Java Servlet Filter Example Tutorial.
I have done #WebFilter which checks to which page user tries to access and if he isn't authenticated (session not created or there isn't attribute user inside the session) he's being redirected to login.html page.
This is relevant code from my login.html page:
<form action="LoginServlet" method="post">
...
input elements for username and password
...
</form>
Form submitting its data to LoginServlet. LoginServlet checks that credentials are correct and if they're correct, redirect it back to the required page. Currently I store required page in the session (it's better to store this in a hidden element inside the form, but I didn't know it when I was writing the code)
I perform redirect from LoginServlet by using this line of code:
response.sendRedirect(redirectToPage);
All pages in my project are simple *.html pages with javascript, I make a mobile web app by using jQuery Mobile.
My problem that after redirect to required page:
It the address bar I see name of the my servlet, LoginServlet while in a console of Chrome I didn't see content of my page, only the name of my servlet, LoginServlet and its content is a blank. But inside the browser I see all static content, it's rendered correctly.
The most important problem that all my dynamic content in a loaded page doesn't work. Dynamic content I mean a few ajax function which should be invoked upon page loading and render dynamic content:
$(document).on('pagebeforeshow',function(){
initPage();
});
If I reload page everything begins to work as it should.
What am I doing wrong?
Thank you in advance.
There are actually a two solutions for this problem.
The first one is to perform redirect in javascript not in servlet, and I think that it's preferable solution, for more details look here: How to manage a redirect request after a jQuery Ajax call
And second solution if you required to do it from servlet after submitting a <form/>, is to add data-ajax="false" into the <form/> tag:
<form action="postthis" method="post" data-ajax="false">, this solution is taken from here: https://stackoverflow.com/a/8631895/947111

How to load the comment form result inside the same lightbox after it is submitted?

I have loaded a comment form in a view using this code:
$comment = new stdClass;
$comment->nid = $row->nid;
$form = drupal_get_form('comment_form', $comment);
print render($form);
And to open the form in lightbox2:
Add a review
It works fine and I am displaying this form in a lightbox using lighbox2 module.
My problem is that when the form is submitted, the entire page is loaded and would redirect to the comment node form which is site_url/comment/reply/node_id
What I wanted to do is if there is an error message on the form, it will remain in the same lightbox that will open and just display the error messages and for a successful submission, it'll also remain on the same form an display a success message.
I have tried rules but it still doesn't seem to work as the page is still being redirected.
Facing the same problem,
But i think https://www.drupal.org/project/modal_forms this module can do the trick i.e. displaying the comment form inside a popup.
you can visit the page and see that it supports this form.

Passing current page url to control with Twig in Symfony

Hi I have a modal contact form on my site that is available on each page of my site. When I render the contact controller on each page I was trying to use this
{% render controller('CorporateSiteBundle:Forms:contactUs', { 'contactOpen': contactOpen is defined, route: app.request.requestUri}) %}
Then on my controller page from all my contact form I wanted to grab that 'route' value that I was sending over. This is what I used:
$request->query->get('route');
But the form just seems to fail when it submits. Can anyone help with where I'm going wrong? Thanks
you should try with
$request->get('contactOpen');

drupal Webform Issue

I have created a tpl file for render the webform node.webform is working fine but after submit it returns to same page rather than goto thanks page. i want to redirect the action to thanks page.
You can actually create your own page that you want your users to be directed to after submitting a webform, and provide whatever links you like on this page. To do this, edit the webform and go to Form Settings. Under Submission Settings, click Customize Confirmation and choose "Redirect to a different page" from the jump menu. Under path, provide the path to this page that you've created.

Resources