Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
Add href in OnClick attribute in html form

I want to redirect to the python flask route home after showing the alert window.

<input type="submit" value="Register" onclick="call(); log();"></input>

Here are both functions.

<script>

  function call()
  {
    window.alert("Congragulations! You Registerd Sucessfully ");
  }
  
</script>
<script>

  function log()
  {
    <a href="/home" > </a>
  }
  
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understood your project correctly, you want to forward the user after he has registered. At the same time, a message should appear that the process was successfully completed.

I think your javascript approach is not sufficient for this, since the data must first be sent from the client to the server so that the process is complete. Here the inputs should also be validated and will likely be processed or stored in some way.

I have written a small example for you, which accepts form data and checks it. If the verification is successful, the user is redirected and a message appears. To forward and display the message I use redirect and flash from the flask package.

Python Flask

import re
from flask import Flask
from flask import (
    flash,
    redirect,
    render_template,
    request,
    session,
    url_for
)

app = Flask(__name__)
app.secret_key = b'your secret here'

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        if username and re.match(r'^[a-z0-9\_\-]+$', username, re.IGNORECASE):
            session['username'] = username
            flash('Congragulations! You Registerd Sucessfully.')
            return redirect(url_for('home'))
    return render_template('register.html')

HTML (index.html)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <nav>
      <ul style="list-style: none;">
        <li><a href="{{ url_for('register') }}">Register</a></li>
      </ul>
    </nav>

  {% with messages = get_flashed_messages() -%}
    {% if messages -%}
    <ul class="flashes">
      {% for message in messages -%}
      <li>{{ message }}</li>
      {% endfor -%}
    </ul>
    {% endif -%}
  {% endwith -%}

    <h1>Welcome {{ session.get('username', 'Guest') }}!</h1>
  </body>
</html>

HTML (register.html)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Register</title>
  </head>
  <body>
    <form method="post">
      <div>
        <label for="username">Username</label>
        <input type="text" name="username" id="username" />
      </div>
      <input type="submit" value="Register" />
    </form>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda