Drupal 7 Multistep forms - Remove save & preview button until last step - drupal-7

I have made a multistep/page form in Drupal (the field type is a multipage group, with multipages nested).
The form is 6 pages, and there is required info on every page. The problem is, Drupal puts a "Save" and "Preview" button on the bottom of every page of the form. Really, you CANNOT preview the form or save it until all required fields are filled out. So when users are going through the form and they hit "save" halfway through or "preview" halfway through, they get a ton of errors.
Is there any way to remove the "save" and "preview" buttons until they are on the last page (i.e. page 6 only)?
Thanks.
EDIT: I am using Field Groups to build my form by the way.

There isn't any module I found to do this, not in it's entirety anyway.
We ended up removing the preview button completely with CSS, and installing a module (Required For Publishing) that allows you to specify "Fields Required for Publish" vs fields required to save a draft. Now there's only 3 fields to save a draft for later, but 20+ fields required to publish the event/form.
We used javascript in the multipage.js form to validate on each step so they can't move on without filling out the actual required fields on each page.

You'd have to make your own module and use hook_form_alter .. https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7 .. and check which step you are currently on .. and then remove the buttons if you are not on the last step .. and enjoy.
Something like .. unset($form['actions']['preview']);

Related

validation if there is any error is present in form then can not go to next page in react

In my form if i enter numbers rather than text and it will give an error then after clicking on next button it should not be redirected to next page.
how to prevent this.
The clicking on the next button will execute a validation function, and based on the result, you will decide whether to navigate to the other page or display an error and stay on the same page.
Even better (and assuming that you have multiple fields in the form): check the value of every field when the user leaves the field (onBlur) and notify the user about the error immediately then. This is not instead of running validation on 'Next' or on 'Submit', since the user may click on the button without visiting that field.
Long time ago (as a test for me, during my study of react), I created a small project that implements a form. It is far from perfect, but you might find it useful: https://github.com/rahamin1/reactstrap-form

Multiple Steps Form in React

I was asked to develop a multi-step form in React. The form contains 30 fields to be filled and it should be displayed in 3 steps of 10 fields each.
The first 2 steps have "Save" and "Next step" options to save the current work or continue with the next step.
The final step has "Save" and "Finish form" options, both of them will save the form in the database (through a web service).
Something like this:
The project is made on React, using Mobx for the state management, and I'm new to react. My question here is... how should i manage the states and the stores?
Should i have a single Store (FormStore) with the 30 fields and pass it to each component through the props and they will fill each field?
Is there any way i can have a single store (like a singleton) and each component fills its fields there?
I have to manage the fields information in memory untill the Save button is hit. And if when the Save button is hit, i need to save just the filled fields.
Any kind of guide will be appreciated.
If this form data is not changed anywhere else in your application, you can use a single store for all. I cannot think of any disadvantage given that it is relatively small.
You would want to split it if the answers could be put in different categories and different categories would be mutated by different functionalities of your app.

Drupal 7: How do I extract specific field in a taxonomy page

How do I extract specific field for display in a taxonomy page?
I have a custom content type called "film" and each film has a Term Reference field called "casting". As expected I can click on a "casting" (tag) it brings me a page where all films are listed wherever this tag is associated. For expample if I click on "Kate Winslet" from movie Titanic, I land on a page http://localhost/mysite/tags/kate-winslet where other movies of Kate Winslet are listed. Up to this point everything is just fine.
I do not want Drupal to pull in and show default fields like just Title and Body in its own display format. Rather I want it so that I can display a photo from each film, year of release and of course the title and trimmed version of the body. I only want to customize the content of this page so that I have the control over What to Show and Where To Show a specific field value.
This is what I tried:
I cloned and put page.tpl.php in my theme's template folder. Renamed it as page--vocabulary--tags.tpl.php. Then I took out the following line of code (<?php print render($page['content']);?>) from my page--vocabulary--tags.tpl.php. The intention was to check whether the overridden template is actually being accessed by Drupal or not. It does!
But I am not been able to extract fields like field_photo or field_release_date from $page['content]. To get an idea about defined variables and how they are placed I used the following line of code:
<pre><?php /*print var_export(get_defined_vars(), TRUE);*/ ?></pre>. But even from there I could not extract a particular field like I mentioned above. The fields look to be somewhere inside $page['content']['system_main']['nodes'], but I don't know how to get to a specific field directly.
I also created a template.php with the following preprocess hook function:
<?php
function introduction_preprocess_page(&$vars) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$term = taxonomy_term_load(arg(2));
$vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
$vars['content'] = $vars['page']['content']['system_main']['nodes'];
}
}
?>
Both <?php print render($content) ?> and <?php print render($page['content']) ?> print the same result but I want something like <?php render($content['photo_field'])?> which I am not been able to.
I am sorry for making this too long. I have just stepped into Drupal. So wanted to make sure that what I am trying to explain matches exactly what I want to accomplish.
You are probably trying the long way to this.
You can use Views module. It allows to create custom listings querying the database, but also override existent ones, like the case of the taxonomy term page listing.
Once you have the module installed (if it's not yet), particularly the Views UI module, go to /admin/structure/views and scroll to bottom, where disabled views (grayed rows) are. You'll find one called Taxonomy term, described as 'A view to emulate Drupal core's handling of taxonomy/term.'
Click Enable on the right of it and then go to the same place where the Enable link is, click the arrow to unfold and choose Edit.
Once you're in the view edit page, you can manipulate the listing at your convenience, adding/removing fields or whatever you want to do in your particular case. If you are not familiar with Views, I recommend you to learn about it, there is a lot of related content on the web and it is close to essential for Drupal development.
Also, if you want to add more customisation to the page, you can use the same approach with the Panels module, who allows to override system pages (not just listings like Views).

In Drupal 7 views how to give external link (another website) to a title?

Iam new to drupal 7 views.
I have a content type contains title, description fields. I want the content title's to scroll at the top of the page, so that i created a view and it works fine.What is my question is, i want to link a content (eg: 1st content (title) in a scroll) to another website instead of content page, the remaining contents linked to the content page. Is it possible?.If it is possible how it can be done?..
Thanks in advance,
A.John Melchior.
Yes, it's possible.
One way to do it, would be to use the Link module to create a link field in your node.
Use the link field to input the external link value.
In views add the link field, before the title ( order is important ) and exclude it from display
Add the node title field in the views and in the rewrite field output option, use one the link field token as your path.
I'm not looking at the Views UI right now , but you should find at least a couple of ways to redirect content when the node title is clicked. You should have the Rewrite field output and the Output this field as a link.
You could make use of Display Suite coupled with the description above.
Create a link field for your nodes.
Create 2 view modes for your content type via Display Suite. View Mode 1 will show the link field as the first data element, View Mode 2 will show the title as the first element.
Configure your view to show output using Display Suite, configured to show the first record using View Mode 1, all others using View Mode 2.

Sales-force Custom Object Edit page layout and Button

We have a custom object say Sales form. On edit apge of customer object we need to add a button Save and Add Product(similar to One we can have on Opportunity page). User forget to add Product/SKU after saving the sales form
New Button(Save and Add product), will save the sales-form first and then depends on record type will open the related list(child object).
Say a Sales form is for Custom Program, after save,. it will open up Custom Program relate list.
If Record type is of Price Change Notification it willl open up related list of SKU detail..
Is this possible, please adivse, we have 9-10 different record type, and we don't want to re-write the application with visualforce and all customization. Re-writing with Visualforce page has some pitfalls.
As far as I'm aware, you can't replace the Save button as it's part of the Edit page and not the standard layout, so to achieve this with one button you'd need to write a custom visualforce page, this need not be complicated though — a simple custom controller which uses a standardController for management of the record would suffice.
You would call Save on the StandardController and then return a different page redirect based on the record type, the page itself would pretty much only consist of an <apex:detail> tag. If you want more details I can provide more.
If you really don't want to write any custom code or pages then you'll need to do this as a two step process, i.e. use the standard page and then have a custom "Continue" button which takes the user onto a custom URL based on the record type. I've just created a contrived version of this by doing the following:
1 - Define a custom formula field on the object, this should be of type text and can use a CASE() statement to determine the URL which the user will be taken to when hitting the button (note that this was made just for the sake of an example so it forwards to the accounts standard page for the record type 'Friend' and contacts page for 'Foe').
CASE($RecordType.DeveloperName, 'Friend', '../001/o', 'Foe', '../003/o', '')
Note the reason I use a formula field here instead of the doing this in the custom button is that for some reason you can't seem
access the record types by name when defining a custom button.
2 - Define a custom button for the object called "Continue" or something similar that makes sense for you. For my example I just used the Contact object, so I referenced the custom field on my record and specified the options shown here:
3 - Customise the page layouts used by your record types to include this new button and you should be done!

Resources