Using Form Wizard with pages that have no forms - django

I am working on a Django project where I have about 7 pages all in order. Basically step 1 - 7. I would like for them to have some sort of navigation/progress bar above the content showing where they are in the pages and how much they have completed. The only thing I have found close to this is using Wizard Form. The only issue I run into with this is some pages do not have a form.
Page 1 = Pure text explaining information
Page 2 = Setup information
Page 3 = Form
Page 4 = Form
Page 5 = Information
Page 6 = Form
Page 7 = Completion/Thanks
Is it possible to still use the Wizard Form for this setup? Or is there a better method of doing what I am trying to accomplish?

I haven't used Wizard form, but they look decent. Here are a few things you can try:
The first way is complicated. From my experience, React libraries like Material-UI have support for a navigation bar, progress bar, and all sorts of transition effects. They are complicated to get started though, and I won't advise you to try this unless you had worked with React before.
The second way is sort of a cheat. If Wizard Form requires a form on every single page, you can use something like this to easily get by:
<form method="GET" action="">
<p>Put whatever you want here. Divs, text, whatever.</p>
</form>
As you might've noticed, it's a form with GET request with no actions and a submit button. In that sense, you can just treat this form as a regular division. If Wizard Forms requires just a form, you should get by with this trick.

Related

Django Form so many fields

I have a Django page using bootstrap and crispy forms that present a form. but the form is growing so much now that I probably have around 50 fields :( which are all within 1 massive HTML page. I'm pretty sure this is the wrong way to do it.
Is it possible to split the forms into say 5 pages, but still have a submit button to post all of the fields to the database?
For now, what I have done is to create tabs for each section of the giant form so it's easy than scrolling.
I'm thinking it's probably better to create different views for each section and then link the data somehow back using an IndexKey or something?
But i have no idea how i would configure the button to capture all the fields.
I know this is a rubbish question, but I don't really know what to search for?
Cheers
You can try to divide the form in bootstrap tabs like
Personal information --> form fields
Additional information --> form fields
Why don't you break the data input down into as many questions as you think is appropriate for each page? If you have 50 inputs, you could do 10 over 5 pages.
After submitting Page 1, return the POST data to Page 2 and store the data in hidden input fields. Repeat the process until Page 5 when you can POST all 50 to the server and insert the data into your Database.

django - how to make clickable html text that sends data to model?

I want to display users around 10 clickable html "tags" (just text with some css that changes when clicked) on my form page. I want them to be able to select a maximum of 3 tags but no minimum requirement. I then want to take the sum of all clicks for each individual tag and do some calculations with them as a model method, like return the 3 most clicked tags.
It's important that my tags are on the form page and are submitted at the same time as the form. So I guess they have to be part of my form.
How would I go about doing this? An actual example would be tremendously helpful as I'm still very new to django and find the documentation (which I've looked at) somewhat hard to understand.
If you know the tags ahead of time, I'd recommend this setup:
Use a multiple select widget in your form (see the favorite_colors field in this Django widgets example)
Use Select2 or another JavaScript library that converts <select multiple> inputs into a tags-like UI
If you go that route, this widget from django-select2 looks like it should get you off to the races.

Creating normal forms in Joomla 2.5

I want to create a simple registration form as one of the pages in my Joomla 2.5 website.
Every where on the internet, I see people asking me to use an extension like proforms, ckforms etc.. Most of the have price tags on them and the free ones do not have database and I don't really want a lot of functionality.
I just want the following code to work. So that I can pull the POST variable and insert them in a db.
<form method="post" action="mycreatedpage.php">
<input type="text"/>
<input type="submit">
</form>
Is this not possible in Joomla 2.5?
After a bit more searching, I realized that what I really needed was an ability to make PHP run inside the article. Thanks to a video.
Answer :
Install Sourcerer to enable PHP inside joomla articles
Create an article which take in the POST variable and insert into the database. This is the tricky part. What I did here was take the general PHP code which I would have written in register_do.php and insert it using the Sourcerer plugin.
Now create an menu Item which points to the above article. Save the menu item and copy the alias. This alias will be the action for the form.
From here on on, everything must work fine.
For more detailed instructions, watch the video
When you post a form, you have to have some code to handle the form input and what to do with it. So your options are to write a component to handle that form input or to use a form component that does it for you. If you write your own there is a lot to consider unless you want to open up gaping security holes in your website.
There are plenty of free forms components available. If you want free, I would recommend Chronoforms, if you don't mind paying small fee then RS Forms.

Multi-page django form - slider or FormWizard?

I have a long form that I want to break into multiple pages.
I am evaluating between two options for presentation:
Present the form on multiple pages using the FormWizard
Present the form on a slider like CSS3 slider.
The slider is actually just one page long using CSS3 to give impression of slides. It floats all of the content areas next to each other, hides the overflow, sets page width to say 500% if we have 5 slides, and moves the left-margin -100% to show the next slide. So it is all one page but seems like the form is being shown on sliding pages.
To me the advantage of slider approach is that there is only one form and the user submits the form only once at the end of slides and thus can go back and forth to make changes.(This is will be a common case).
Versus having mini-Forms for FormWizard and submitting them after each page. To me, FormWizards seems complicated especially if the user wants to change any of previous page responses. I also need FileField on my form pages and it seems like FormWizard accepts FileField only on the last page.
However, I have not seen many folks use this sliding forms (CSS3 or JScript one) approach. Hence, as a newbie, I am wondering if there are some obvious pitfalls of doing this?
I can only write about FormWizard as I have used it before. According to 'Handling Files' section of Django documentation which can be found in
https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
a FileField can be used in any step of your FormWizard implementation. What I found really helpful by using FormWizard from Django, is that it provides you all the standard functionality of Forms. That means that you can easily create and manipulate forms, validate fields in each step, etc. I am not aware of how CSS3 slider accomplishes validation, but I guess that validation should take place on client side.
Additionally, Django's FormWizard uses either a Cookie storage backend, or a Session storage backend in order to store information, which makes the navigation between steps and modifying previous stored data pretty trivial.
I hope I helped you in your decision! A lot more information can be found of course in the Django documentation of FormWizard in the link I provided above.

Events in Django

This might be a very dumb question but I can't find an answer anywhere. I was wondering how do you handle events in Django. I've read the tutorial in their webpage and I cant find a sign of explanation or I'm missing it.
I work in ASP.NET webforms and the way to do that, as you probably know, is putting the event name in the ASP.NET control and calling a particular procedure. I know Django is a very different framework because it's MVC, but I have taken a quick view to a ROR tutorial and I think I've seen they use something similar to ASP.NET webforms, if I've understood correctly, something like embedding ruby code in the html interface and declaring an action there, which I suppose calls the respective function, something like this
<%= ..., action:'action1', ...%> ,which calls a function 'def action1:' in the controller, similar (only in that sense) to asp.net, but webforms doesnt render a view with the name of the function among other things.
So the question is simply that, how do you use events in Django. I hope I was at least a bit clear because it's difficult for me to ask these questions in english
I'm a former ASP.NET developer who switched almost entirely to Django, so I know exactly what you're asking about.
Probably the simplest way I can explain it is this: What you're thinking of as an 'event' would be a URL AND View in Django. Abstract down what you were doing in ASP.NET and it'll make sense -- You had a control, which was just an element on a page. That was mapped to an event, which was really nothing more than a function. So the model of what you're doing looks like this:
object > method
In Django, it's similar, but there's an extra step. ASP.NET automatically connected the object to the method. In Django, you'll need to do that yourself. You do so by creating a URL for that object (urls.py), and then assigning that URL to a view (views.py) which is really nothing more than a method. In Django the same model looks like this:
object > url > method
In many ways they're achieving the same end effect -- something happens and it's handled by a method on the server. Django is simply a bit more open and lets you configure how it happens (and requires that you understand that and handle it yourself).
This concept of control (TextBox, Button, etc.) and page events, in the way you describe, is not carried over to most other frameworks. This was all part of Microsoft's attempt to make the web development experience very similar to that of developing Windows applications -- for better or for worse.
For instance, in a WebForms application:
button.Click += Button_Click;
private void Button_Click(object sender, EventArgs e)
{
// handle action here
}
Would roughly correspond to something like (client-side, in a template):
<form action="/myaction" method="POST">
<input type="submit" value="Click me" />
</form>
Server side view:
def myaction(request):
if request.method == "POST":
# handle action here
pass
In other words, what you want to do in Django and indeed in other MVC frameworks is have unique "actions", or methods, on your controller classes (or view functions in Django). These actions generally respond to HTTP GET and POST requests.
If you want client-side events on your controls, you'll want to look at using a JavaScript framework such as jQuery.
You do this in the view, dependent on the values of the request.POST dictionary.
For example, say you have two buttons on the HTML form, one with name="submit" and one with name="add". Then, in your view, you can do:
if 'add' in request.POST:
# do add action
elif 'submit' in request.POST:
 # do submit action
This is exactly how the admin app manages the difference between the "Save", "Save and continue", and "Save and add another" buttons.