FAQ Page



  • Django - form data

    ************* HTML FORM **************

    <!--<form method="POST" >-->
                                <form action ="" method="POST" data-sb-form-api-token="API_TOKEN">
                                {% csrf_token %}
                                <!-- Name input-->
                                <div class="form-floating mb-3">
                                    <input class="form-control" id="name" name = "f_name" type="text" placeholder="Enter your name..." data-sb-validations="required" />
                                    <label for="name">Full name</label>
                                    <div class="invalid-feedback" data-sb-feedback="name:required">A name is required.</div>
                                <!-- Email address input-->
                                <div class="form-floating mb-3">
                                    <input class="form-control" id="email" name = "email" type="email" placeholder="name@example.com" data-sb-validations="required,email" />
                                    <label for="email">Email address</label>
                                    <div class="invalid-feedback" data-sb-feedback="email:required">An email is required.</div>
                                    <div class="invalid-feedback" data-sb-feedback="email:email">Email is not valid.</div>
                                <!-- Phone number input-->
                                <div class="form-floating mb-3">
                                    <input class="form-control" id="phone" name = "ph_num" type="tel" placeholder="(123) 456-7890" data-sb-validations="required" />
                                    <label for="phone">Phone number</label>
                                    <div class="invalid-feedback" data-sb-feedback="phone:required">A phone number is required.</div>
                                <!-- Message input-->
                                <div class="form-floating mb-3">
                                    <textarea class="form-control" id="message" name = "message" type="text" placeholder="Enter your message here..." style="height: 10rem" data-sb-validations="required"></textarea>
                                    <label for="message">Message</label>
                                    <div class="invalid-feedback" data-sb-feedback="message:required">A message is required.</div>
                                <!-- Submit success message-->
                                <!-- This is what your users will see when the form-->
                                <!-- has successfully submitted-->
                                <div class="d-none" id="submitSuccessMessage">
                                    <div class="text-center mb-3">
                                        <div class="fw-bolder">Form submission successful!</div>
                                        To activate this form, sign up at
                                        <br />
                                        <a href="https://startbootstrap.com/solution/contact-forms">https://startbootstrap.com/solution/contact-forms</a>
                                <!-- Submit error message-->
                                <!-- This is what your users will see when there is-->
                                <!-- an error submitting the form-->
                                <div class="d-none" id="submitErrorMessage"><div class="text-center text-danger mb-3">Error sending message!</div></div>
                                <!-- Submit Button-->
                                <button class="btn btn-primary btn-xl" type="submit">Send</button>

    ******************  VIEW CODICE *****************************
    from . import models
    from django.shortcuts import render, redirect

    def uploadFile(request):
        if request.method == "POST":
            # Fetching the form data
            fileTitle = request.POST["fileTitle"]
            uploadedFile = request.FILES["uploadedFile"]

            # Saving the information in the database
            document = models.Document(
                title = fileTitle,
                uploadedFile = uploadedFile
        documents = models.Document.objects.all()

        return render(request, "Core/upload-file.html", context = {
            "files": documents

    def index(request):
        message = ''
        if request.method == 'POST':
            f_name = request.POST['f_name']
            email = request.POST['email']
            message = request.POST['message']
            #return redirect("Core/index.html")
            message = message + email + f_name

        return render(request,"Core/index.html",{'sum': message})
    # Create your views here.

  • Rif. 863