Attach or embed node add form with a view - ajax

I am using Drupal 7.54. I want to attach or embed a node add form to a view so that when a user submits the form, the view below the form will be updated in realtime via ajax. The form will be shown above the view. My view block name is Statuses Stream.
I tried Form block module and putting the form in the header section of my view using views ui, but after submit, it was redirecting to the node created page.
Then I tried Advanced Form Block module. I created a form using AFB module. The form name is Statuses. It is submitting the form with ajax, but it is not updating the view in the realtime. I have to refresh the page manually to show the created node below the form.
I am open to any solution programmatically or through a module.
Note: For those who know, I am trying to mimic the statuses module. It does exactly what I am looking for. The problem began when I came to know that it is not an entity. So now I am trying to make the same functionality with Content type.

You could use something like Views Refresh to manually update the view below instead of refreshing the page.

Related

Show bootstrap modal on server side validation

I have a ASP.Net Core MVC web application. I have a standard razor view which has a list of items with a delete button. What I want to do is if they user deletes an item from the grid go to the server calling an action which validates the item selected. IF invalid I want to return to the view and show a bootstrap modal explaining why the delete cannot be carried out. I call the delete routine using Controller / Action tag helpers and pass the unique Id to a controller event.
So basically if my delete validation fails show a modal dialog with a message. Any help please?
I ended up sorting this myself. Basically I set a viewbag property and give it a value of show. Then in my script section of my view I set the modal property to that viewbag.

What is the best way to place 2 forms on the same page?

What is the best way to place 2 identical forms on the same page, but use the same form action and fields for each form? How can I keep response messages in the respective form area from which the data was submitted?
I'd have one form in the footer of my site, and one form in a popup on the home page of my site. I'm using a hidden div and Magnific to open the popup containing the same code from the form that is located at the footer. Essentially, both form do the same thing, and utilize the same form action.
I do not have access to the form action, or the code in the form action page.
Currently, the forms existing on the same "page" are no problem, but when I submit an email on one form, the errors and success messages show up on both the popup form as well as in the footer form.
I've read that this may be possible to do with ajax, but for completeness sake, I want to make sure that I'm building that I'm doing what I can with the form html, before moving on to studying ajax for this.
Sadly there is no nice html/liquid solution for this.
The only way is to use cookies in order to save information which form was submitted and show the error message only for that form instead of the two ones.
AJAX is not a good solution because of the Google Recaptch-a when you submit the form more than once, which is a real pain in the a** since there is no way to disable it and the form will fail if you try to submit it with ajax.
The easiest solution is to use cookies, other option is to rely on an APP for this, but it may be an overkill for this.
Forms in Shopify are... how to put it nicely... dumb... basic... not developer friendly or just not made to be tweaked in any sort of way ( excluding the front-end ).

MVC 3. Load menu and content separately

I have an app with 3 sections:
Main menu;
Context Menu - Related to selected item in main menu;
and Page body - Related to selected item in context menu;
"Main menu" and "Context menu" are based on membership. I don't want to load them everytime my page loads, because that would consume resources database. So, I'm using ajax to load main menu only one time, and when an item is selected, I load the context menu for that item.
My problem is: Every form's post will erase my menu.
Question: Will I have to build my entire application using ajax? I don't wanna do that, because it is too much simpler do a post in the form then send all data to controller with ajax.
Until now, I have 2 options:
Load my menus with ajax and the page body with IFRAME, so the post's will not render again my menus.
Do everything using ajax;
Is there any alternative to load my menus with ajax and be able to use form's post?
Sorry if I wasn't clear enough.
The sentence that gave me a pause is this "I don't want to load them everytime my page loads, because that would consume resources database."
You see, I've build quite a lot of apps, that display menus and sub-menus based on user roles (what you called membership). This has never been an issue from the resources or database perspective.
You can access all the membership information that you need once, when your used is being logged in. In the simplest case user's identity will be stored in the context along with the roles they have (HttpContext.User), so you do not to need a database lookup at all to get this information on every request. Note that with this scenario no ajax is required either.
If for whatever reason you can't store your membership information in the context like this, you still can store in in session (if in-memory) or in encrypted Cookies.
Now, I understand, that I don't all the details of your scenario, and that may be in your scenario what you are trying to do is warranted, however I suggest you think it through again, as under normal circumstances what you indicate is a problem (database resource) should not be a problem at all.
The bottom line is: if you alter your application that it stores the membership information when user logs on you won't have your problem to start with.
You don’t have to build all of your application using Ajax. But in this scenario Ajax may be the best way forward.
Following is my suggestion
Create your data entry for inside a dev
Have each input controller marked with a class (say ‘dataEntry’)
Create a javascript function to iterate the dev and build a list of all elements that has class dataEntry
Build a json object using the list. Use the name of each element as property name and value as the property value
Use jquery ajax to post this to the controller action
[optional] you can use .done and .fail methods to take action on success or failures of the call
I know this may look intimidating, but if you have many data entry forms, you can re-use this code.

asp.net mvc3 formauthentication,custom role provider-Jquery auto load tabs not working..

I am creating dynamically loading tabs using jquery Ui tabs in my ASP.NET mvc3 project.
Here i have a product page. The product page contains left menus like Customer,Address,Contact,etc..
Here my process is when i click one my left menus, the tab created dynamically with Grid records.
And,
I'm creating a custom role provider and I set a Authorize attribute specifying a role in my controller and it's working just fine, like this:
[Authorize(Roles="SuperAdmin")]
public class SuperAdminController : Controller
...
If one user doens't have access to this controller, And click one of my left menu means,
he's redirected to login page. Its also working fine.
The problem is after the user logged in it didn't redirect the proper page in tab content area.
If my problem not understandable means please let me know..
Thanks Advance...
If you carefully check the URL in the browser, you will see that the URL does not change when you load something by Ajax. That is the point of Ajax actually, you do not load the whole page, right?
Now as the state is not saved when you try to load the content using Ajax, your redirect URL is only the page you loaded initially. That is why you cannot go back to the tab you wanted to load.

CakePHP Ajax Add form from View (related )

i´ve got a view of my client (http://localhost/client/view/3) and in related section I have his adress.
Cakephp automatically builds that. When you click on Add Adress button new page comes up (http://localhost/addess/new) and when you save that it goes to http://localhost/addess/index
what I need is to ajax this view and get all working together. I need to go to http://localhost/client/view/3 push Add Adress and get addrees/new form visible (<- easy with jQuery) but how can I save the new adress and get adress div updated??
any example??
thanks
The php script you make the AJAX call to is where you need to do the save. When you have done that, you can pass out the data for the address div as xml or a javascript object and read it with the AJAX javascript in the original view.

Resources