Disable Drupal redirecting to page view after edit - drupal

How do I disable the edit page redirecting to either the page view or the list of site contents upon saving?
I prefer to keep the edit page open whilst refreshing the page view in another browser window, and it is really annoying having to click back into the edit view every time I click on 'Save'.
I cannot find anything in the documentation or online telling me where I can turn off this behaviour ?

If you want this behaviour both on node creation and update, and for every content-type, you can do something like:
function hook_node_insert($node) { // and for hook_node_update
$_GET['destination'] = 'node/' . $node->nid . '/edit';
}
EDIT : Of course I don't know your Drupal level so I didn't say that you have to put it in a custom module, etc, etc. If you need more information about that, just ask ;-)

Use this module, it adds an extra button to save and stay in edit: https://www.drupal.org/project/save_edit

Related

Drupal + Views Slideshowplugin?

I have a question, but the problem is, I can't show the page right now, because it's only on my local server. I will try to explain it as good as possible.
I've got a view that makes my frontpage have the full content of my nodes. So you see a node(in this case an embeded youtube link). You can then go to the next node via "next" or to the previous one via "previous", etc. The problem I have and I don't know how to fix is:
I got a gallery below(another view), of all my nodes, so you can either click through the prev and next buttons, or click on one of the pictures in the "gallery". But when i click on the galery, it goes to the node links so lets say "site.com/node/44".
Is there a way I can go to the node/44 page and still be able to click prev and next? And moreover, can I use the Slideshow plugin by views with changing links? Because it's just says "#" in the url... Like it does with the main content when i click "prev" and "next"?
I hope you can understand what this is about :-). If not, please feel free to ask for further information.
So your explanation is a little "garbly" so here's my somewhat 'not-so-garbly' response:
Sounds like your understanding of views is a little low. Make sure you're Displaying fields in your view and not just full nodes or teasers.
Next, if your desire is to show the gallery on all the nodes of the same type, you can so by creating a block display in views and configuring that block to show up ONLY on the node type you desire.
It gets complicated when you (which appears to be your desire) want the view to start from the last point you were viewing. This will require rewriting the field (this is available via the field configure form) which contains the image. You'll have to add a parameter (probably the current nid) which can be added, hidden, then accessed as a token via the Views Fields interface as well.
I don't remember exactly how to get the view to display the current (or next) slide by default once it's clicked.. but this is probably how I'd do it:
pick up that parameter in JS / JQ and use it to find the slide you want to display... then fire the JS function needed to display the desired slide.

Is there a Drupal module that can redirect from root URL to a certain page?

I wonder if there's a Drupal module that can do this kind of functionality: if i go to home page, it will take me to some subpath within the site. i.e. www.something.com will redirect to www.something.com/product/node/11.
I tried creating an alias and used Path redirect module but for some reason, i can't reach the expanded URL when going to home page. it will display the content of www.something.com/product/node/11 but still using www.something.com.
I'm thinking that this can only be implemented in Apache server, not inside Drupal?
Note that our purpose of doing this feature is whenever a new product is created, we want our home website to point to that (i.e. www.something.com -> www.something.com/product2/home, before www.something.com/product1/home). If this is configurable inside Drupal, the changes would be easier and can be done by a Drupal administrator.
You should be able to go to /admin/settings/site-information and set the Default Front Page at the bottom of the form. That doesn't do a redirect: the home page will BE whatever you set the default to.
Create a new view (Node type) named "frontpage_redirect"
As suggested in answer by Michael D, create and save a view configured to search for your specified criteria:
display: page display, path = frontpage-redirect
pager: 1 item
row style = Fields
fields: Node => Node ID
filters: node type = product
sort: post date desc
Save your new view
At admin/config/system/site-information, set your "Default front page" to the view display path above (frontpage-redirect in my example)
In the view edit screen select "Theme: Information" link in the Page display. Look for the most specific (rightmost) entry under "Field Node: Nid (ID: nid)" - should be something like views-view-field--frontpage-redirect--page-1--nid.tpl.php, but will depend on the view name and display name. Copy the default views template views-view.tpl.php into your theme folder using the filename from 3.
Edit the template and put this code in it:
if (isset($row->nid)) {
drupal_goto('node/' . $row->nid);
}
This way of setting up the redirect lets you drive it from Views, which gives flexibility. When your customer decides in six weeks that they want to feature only the latest red product on the frontpage, you'll be able to update the logic behind the redirect using the views UI. (And you can do it from your phone on the train home!)
You avoid the need to create a custom module (which is easy enough, but does add some complexity) or to move your site logic into .htaccess.
Using the Views module, create a new view that displays one full node, ordered by last created, filtered appropriately, then create a page display in the view. Then follow Graham's instruction to set the site homepage to the view URL.
Another way would be to write a very simple custom module that db-queries for the latest node created of the sort you want, grab the URL to the page, then redirect there using drupal_goto().
There are other ways to do what you want inside Drupal, but I can't think of any that are more direct and simple at the moment...
What you are asking seems wrong. Sorry if I misunderstand some detail, but it seems you should reconsider the problem on a higher level.
If I understand you right, you want to show the page for the latest product as the homepage?
If so, maybe you should turn that into show the latest project page on the homepage. That fits a lot better with the RESTfullness of the web. And with expectations of the users.
The pattern would then be:
GET /products/22 shows product 22
GET /products/23 shows product 23
GET /product/latest shows the last product (in this case, the page would be exactly similar to /products/23)
To achieve that, you can use views module.
On similar lines to Michael D's post, assuming you want to pull the most recently published product from a custom content type called "products," you could put something like this in your settings.php:
function yourtheme_preprocess_page(&$variables) {
$query = db_query("SELECT nid FROM {content_type_products} ORDER BY nid DESC LIMIT 1");
while ($row = db_fetch_object($query)) {
$redirect_nid = $row->nid;
}
if ($variables['is_front'] == 1) drupal_goto("/node/" . $redirect_nid);
}
modify the .htaccess file.
http://drupal.org/node/50322#comment-2456576

wordpress form action submit

have an own customized form in wordpress.
action=<?php bloginfo('template_url'); ?>/send_form.php"
on submit, it goes always to send_form.php
but this php is for sending the info - and i cant style with with the theme....
is there a way to stay on the current page while it sends the info and print out and message in a field that the form has been sended succesfully???
anyone have some suggestion for me?
The answer to this is quite involved and getting it right takes a little care, but here are the essential points of one approach:
The action must be set to load the current page and you can do this by changing the action attribute in the <form> tag to: action=""
In the template file for this page, detect when the page loads after a form submission. You can do this by checking the state of the $_POST variable.
If there are post variables, process the form submission in the template file. You need to look at what happens in "send_form.php" to figure out what to do. Take care that you don't introduce security issues (e.g. be sure to use the NONCE).
Redirect back to the same page to get rid of the post variables. If you don't do this people will get those "Do you want to resubmit the form" warning messages. See the PHP header() function for doing the redirect and note that this must happen before any output is sent to the page.
Use server sessions to display a "Form submission successful". Set a session variable to your message before the redirect, then detect it when the page loads, display it, and remove it so the message doesn't display the next time the page loads.
That should give you a starting point.
If anyone else has a simpler solution, I'd love to hear it too.
If you want to do it through plugin instead of the theme, then use "admin_post"(admin_post_YOUR_ACTION) and "admin_post_nopriv" (admin_post_nopriv_YOUR_ACTION) actions. (Btw, you can use those actions through theme also)
Here is a good explanation: https://www.sitepoint.com/handling-post-requests-the-wordpress-way/

Require anonymous user to register to add content-type

How can I create a form that requires anonymous viewers to register in order to view it?
Right now, I've created a content-type (Submit Plan) which is a primary link available to everyone (anonymous + authenticated). I've restricted 'view' user permissions to anonymous users but they can still see the 'Title' input (I don't want that).
I'd like it so that when an anonymous user clicks on 'Adding a Plan' primary link (the Submit Plan content-type), it goes to the page and says:
"You must register for an account" OR
Redirects them to the registration page asking them to register to submit a plan.
I've been searching for a module or maybe some code to use but have come up short on this topic. Any help would be appreciated. Thanks!
If you're going to be redirecting users to the registration page, I'd strongly consider using something like logintoboggan to make the registration > node-creation process smooth. Otherwise, registration is a multi-step process and I'd imagine it being easy for users to lose their way back to the Add a Plan form in the process.
For the "show links or show the form" direction, there are at least two ways of approaching that: 1) create a custom page where you "import" the add_plan form (or show the links). 2) modify the node/add/plan page itself, either through themeing or the fapi (the forms api).
Here's a promising looking post for the first method: http://drupal.org/node/357895.
Here's a place to start with FAPI http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
Here's a post about theming the node form: http://11heavens.com/theming-the-node-form-in-Drupal-6
Without having tried this, I'd probably lean toward method one.
Update: just had another thought: you could also add the plan form to the registration form so they'd fill them out in one shot. I'm not sure of how to do that in general, but the node profile would work if they're only ever going to make one plan, and if not, you can look at how that's put together.
This can be done a few ways.
One, in your menu output, you can change the link to Submit Plan like this:
<?php
global $user;
if ($user->uid == 0) {
print 'Add a Plan';
} else {
print 'Add a Plan'l;
}
?>
The above code looks to see if the user object has a UID. 0 is anonymous, so that will print the link that sends them to register. Otherwise it will take them to the node add form for Submit Plan content type. This also assumes you control your own menu output. You can also override it in a similar manner by using a theme function.
There are a few ways you can do this, so start there and let me know what you think.

Drupal and Comment Form

I need to insert the comment form directly to the node template (I use node-type.tpl.php to theme the node-type).
In related issue, if I go to /comment/reply/NID I get the comment form, but it's got only "preview" button, and no submit button. the Preview button does nothing when pressed on.
Thanks for the help!
Check your node-type comment settings under 'admin/content/node-type/yourNodeType'. Within the (normally collapsed) fieldset for the comment options, you can choose whether to display the comment form on a separate page or on the same page as the node.
As for the missing submit button, you can change the setting for 'comment preview' from mandatory to optional.
As for the preview button doing nothing, this sounds strange and I have no idea what might cause this - pressing it would normally lead to a preview of the entered comment, with the option to finally submit it. If this problem persists, you should open a separate question for that.
Comment form is not in scope in node-type.tpl.php. Technically you could add it there trough variable preprocessing. But that will introduce a whole new set of problems.
So, unfortunately, you will need to do a step back, and theme the comment-form elsewhere.
node
node-content
comment-form
comments
is not possible
node
node-content
comment-wrapper
comment-form
comments
however, is the way to go.
see http://api.drupal.org/api/drupal/modules--comment--comment-wrapper.tpl.php
for a starter

Resources