Home > Mobile >  Pass data to another html and save
Pass data to another html and save

Time:12-25

can someone please tell me how to send all content of input.html to approve.html. I want the approve.html to validate input.html and then save it to the database. How can I do that? I'm a newbie, please help me, I've been trying to solve the problem for 7 days.

<form action="/my-handling-form-page" method="post">
  <ul>
    <li>
      <label for="name">Name:</label>
      <input type="text" id="name" name="user_name" />
    </li>
    <li>
      <label for="mail">Email:</label>
      <input type="email" id="mail" name="user_email" />
    </li>
    <li>
      <label for="msg">Message:</label>
      <textarea id="msg" name="user_message"></textarea>
    </li>
    <li>

      <button ><b>send</b></button>
    </li>

  </ul>
</form>
<form action="/my-handling-form-page" method="post">
  <ul>
    <li>
      <label for="name">Name:</label>
      <input type="text" id="name" name="user_name" />
    </li>
    <li>
      <label for="mail">Email:</label>
      <input type="email" id="mail" name="user_email" />
    </li>
    <li>
      <label for="msg">Message:</label>
      <textarea id="msg" name="user_message"></textarea>
    </li>
    <li>

      <button ><b>save</b></button>
    </li>
    <li>

      <button ><b>remote</b></button>
    </li>

  </ul>
</form>

I use django

CodePudding user response:

When views.py send the email, the link should have the data you want to pass as query parameters:

youdomain.com/approve.html?user_name=JaneDoe&[email protected]&...

When the user clicks on the link in the email and arrives at youdomain.com/approve.html, a javascript script can be run to extract the data from the URL and insert it into the approve.html form.

Javascript to extract data from QueryString:

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');

CodePudding user response:

Rather than sending the email and sending back the data from user to you, why not save it in database with an extra field named approved False. Like this:

class UserComment(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(...)
    message = models.TextField(...)
    email = models.EmailField(...)
    approved = models.BooleanField(default=False)

On upon storing, you can generate a link with the uuid for the database entry and send it to user for clicking for validating. If he validates, then just make the approved field True.

  • Related