I created a button in html file that move to page with form:
<a class="btn goToProfile" href="{{ url_for('new_meeting', dog = dog[0] ) }}">Click here to schedule a meeting</a>
I add the parameter dog to the GET request
http://127.0.0.1:5000/new_meeting?dog=123
When I move to the new page I have a form:
<form action="/favorites/add_meeting" method="post">
<label for="time">Time:</label><br>
<input type="datetime-local" id="time" name="time">
<br>
<br>
<label for="place">Place:</label><br>
<input type="text" id="place" name="place"><br>
<br>
<label for="place">Dog ID:</label><br>
<input type="text" id="dog" name="dog" value="1" readonly><br><br>
<br>
<input type="submit" value="Submit">
</form>
How can I extract the parameter from the URL and add this to the value in the input tag?
You can find here about how to get query parameters with JavaScript
When you have parameters let's say inside dogName variable. You can change form input field with id dog like this:
document.getElementById("dog").value = dogName
I'm new to JavaScript and I want to log in to a webpage. This code will take me to the web page but won't sign in. I know it knows the values of username/password because if I do alert(loginForm.elements["username"].value) it displays "someUsername".
I'm not sure how to get these values to be entered into the boxes and hit submit. Any advice helps, thanks!
<script>
function login() {
document.loginForm.action = "http://websiteToLoginTo.com";
document.loginForm.submit();
}
</script>
<body onLoad="login()">
<form name="loginForm" method="post">
<input type="hidden" name="username" value="someUsername">
<input type="hidden" name="password" value="somePassword">
</form>
</body>
The website I'm trying to connect to has this:
<form action="/Authn/UserPassword" method="post" name="loginForm">
<input id="username" name="t_username">
<input id="password" name="t_password">
<input type="submit" name="login" value="Login" class="submit">
</form>
I am trying to send someone an email through a form on my website. I want to include a part of my webpage into the email.
To do this I use a hidden field, which I try to fill using a piece of javascript. However due to my lack of knowledge the code doesn't seem to be triggered.
<form action="Emailverstuurd.php" method="POST">
<input id="ExcelForm" type="hidden" name="ExcelForm"/>
<input name="email">
<textarea name="body" rows="10" cols="60"> </textarea>
<script type="text/javascript">
$("#send").submit(function() {
$("#ExcelForm").val($("#myExcelDiv").html());
}
</script>
<input type="submit" name="send" id="send" value="Send Your Message"/>
</p>
</form>
How can I get my javascript code to run?
You can do it like this:
<form action="Emailverstuurd.php" method="POST" onsubmit="submitUpdate()">
<input id="ExcelForm" type="hidden" name="ExcelForm"/>
<input name="email">
<textarea name="body" rows="10" cols="60"> </textarea>
<script type="text/javascript">
function submitUpdate()
{
$("#ExcelForm").val($("#myExcelDiv").html());
}
</script>
<input type="submit" name="send" id="send" value="Send Your Message"/>
</p>
</form>
Just add an onsubmit handler to your form field give it a function and just put you value update in that function...I don't see #myExcelDiv I'm assuming that is defined somewhere else in your code?
I have a simple HTML form with a name & email address field and a submit button.
After filling in the form and submitting it, I want a message such as "Thank you for your response" to appear on the same page.
I'm looking for a easy clean PHP fix for this. I want all the code to stay on one page (Not separate it into two different files).
I've been searching on Google, but they have much more complex situations.
Your help is greatly appreciated. Thanks.
EDIT: I want the form to disappear after pressing submit and just show the "Thank you for your response" message. I forgot to mention that. Sorry.
<form>
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
Would something like the following help? Essentially, when you hit submit, some special variables are set in the $_POST array, and you can access those. If those variables are set when we're building the page in PHP, then we can do some processing/send an email/show a different response page.
<?php
if (array_key_exists($_POST['your_email'])) /* and other validation */ {
?>
<p>Thanks!</p>
<?php } else { ?>
<form action="POST">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
<?php } ?>
please try below code.
<?php
if($_POST) {
echo "Thank you for your response";
}
?>
<form name="test" action="" method="post">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
in you form validate page
header('location: ../page.php?case=Thank you for your response');
in your page
<?php print $_GET['case']; ?>
What I would like to achieve:
A index page (index.html), which allows the user to register, which runs on JavaScript (index.js) to check the fields (not mentioned in snippet index.js), and then to redirect to a register page (scripts/register.php), which then adds the values to the database.
What is actually happening:
It redirects to the PHP page correctly, however none of the values seem to be transferred when using the $_GET method: I get an empty page.
What am I doing wrong?
Code:
index.html (only a snippet)
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
<script type = "text/javascript", src = "index.js">
</script>
index.js (only a snippet)
document.getElementById("signup").onclick = signup;
var aref = "refcode";
function signup()
{
window.location.href = 'scripts/register.php?emailaddress=' + document.getElementById("email").value + '&username=' + document.getElementById("user").value + '&password=' + document.getElementById("pass").value + '&aref=' + aref;
}
scripts/register.php (only a snippet)
<?php
echo $_GET['emailaddress'];
echo $_GET['username'];
echo $_GET['password'];
echo $_GET['aref'];
?>
EDIT: I accidentally copied the wrong code for 'scripts/register.php', sorry to all the answers who corrected it for me
You're never submitting the form (because you don't seem to have one), thus never getting anything but the data that you embed into the URL (which is very unsecure, not a good idea to send sensitive data like passwords like that).
I'm not sure, however, why are you complicating things like that.
If you want to use GET, no need to build the URL yourself, just set up the form with GET method and use regular submit to send it, no javascript needed. Use the hidden field for the aref value (you can populate it when the form is generated, before submitting, etc, whatever works for you):
<form method="GET" action="scripts/register.php">
<input name="aref" type="hidden" value="refcode" />
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
</form>
Again, changing the method to POST would be a much better idea. Of course, then you need to access the variables like $_POST['aref'], etc. Just like this:
<form method="POST" action="scripts/register.php">
<input name="aref" type="hidden" value="refcode" />
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
</form>
And the PHP (for POST):
<?php
echo $_POST['email'];
echo $_POST['user'];
echo $_POST['pass'];
echo $_POST['aref'];
?>
Your fields are not named the same way in the URL and in register.php. Try this.
<?php
echo $_GET['emailaddress'];
echo $_GET['username'];
echo $_GET['password'];
echo $_GET['aref'];
?>
window.location.href = 'scripts/register.php?emailaddress=' + document.getElementById("email").value + '&username=' + document.getElementById("user").value + '&password=' + document.getElementById("pass").value + '&aref=' + aref;
To access them:
$_GET['username']
$_GET['password']
etc...
In your code you never use the good variable names:
<?php
echo $_GET['email'];
echo $_GET['user'];
echo $_GET['pass'];
echo $_GET['accountref'];
?>
For an Solution without JS, and PHP instead:
<form action="scripts/register.php?<? echo $refcode /* HERES YOUR REFCODE */?>" method="GET">
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
</form>
The normal way to do what you want is using method Attribute in your form or the .submit() event in jquery. I'll show how I would do that:
HTML
without javascript using POST
<form method="post" id="login_form" action='register.php'>
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
</form>
php using $_POST
$user = isset($_Post['user']) ? $_Post['user'] : NULL;
$email = isset($_Post['email']) ? $_Post['email'] : NULL;
$pass = isset($_Post['pass']) ? $_Post['pass'] : NULL;
HTML using Jquery
<form id="login_form" method="post" action="">
<input name="user" type="text" id="user" size="25" />
<input name="email" type="text" id="email" size="25" />
<input name="pass" type="password" id="pass" size="25" />
<input type="submit" name="signup" id="signup" value="Sign Up" />
</form>
<script type = "text/javascript" src = "index.js"></script>
//You have a type with a comma
JS
$('#login_form').submit(function(e){
var data = $(this).serializeArray();
$.post('register.php',data,
function(result){
//Your callback function
})
})
NOTE
My advise to you is that you should use POST method in this case
GET requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause.
and
POST submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
So essentially GET is used to retrieve remote data, and POST is used to insert/update remote data.