skip to Main Content

In Index.html page I have a simple form for only NAME input with a Submit button, and in the next page Details.html how to display that NAME?

I’ve tried with dictionary, but do not know the process of how to get that form data.

2

Answers


  1. Try using it with PHP

    in the index.html file:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Formulário</title>
    </head>
    <body>
        <form action="details.php" method="post">
            <label for="name">Nome:</label>
            <input type="text" id="name" name="name">
            <input type="submit" value="Enviar">
        </form>
    </body>
    </html>
    

    create a file called details.php

    <!DOCTYPE html>
    <html>
    <head>
        <title>Detalhes</title>
    </head>
    <body>
        <?php
            if ($_SERVER["REQUEST_METHOD"] == "POST") {
                $name = $_POST["name"];
                echo "<h1>Nome: " . $name . "</h1>";
            }
        ?>
    </body>
    </html>
    

    Make sure you have a properly configured PHP server to run the code. You can use a local server like XAMPP or WampServer to test the code.

    Login or Signup to reply.
  2. You can follow this steps :

    1. create app_root/template/index.html
    <form action="{% url('datapost') %}" method="post">
        <input type="text" name="name" id="">
        <input type="submit" value="submit">
    </form>
    1. need to create app_root/app_root/views.py
    <pre>
    from django.shortcuts import render
    from django.http import HttpResponse;
    
    def index(request):
        return render(request,'formpost.html')
    
    
    def formdata(request):
        if request.method == "POST":
            name=request.POST.get('name')
            return render(request,'Details.html',{'name':name})
    
    </pre>

    in url.py need to create URL
    first of all, import your views

    from my_app import views
    after that create url.

    you can also follow this >> git_code

    https://github.com/A28V/howtopost

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search