I have a simple form:
<form class="form-contact-warp form-calc-ship cb-form" action="javascript:redirect();">
<input class="form-control" required="" id="textBox" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<button type="submit" class="btn-main-color btn-block"> Create page</button>
</form>
If I put in input field the text daniel, I want to append a link.
Example:
I put daniel in and I click submit. I want to appear below the link
www.example.com/daniel and the text This is your link.
Thanks
I think the best way to do this is to use jQuery or JavaScript by itself:
<form class="form-contact-warp form-calc-ship cb-form" action="" method="post">
<input class="form-control" required="" id="textBox" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<button type="submit" class="btn-main-color btn-block"> Create page</button>
</form>
<div id="response"></div>
<!-- add jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function(){
$('form').on('submit',function(e){
e.preventDefault();
$('#response').html('This is your link:<br />http://www.example.com/'+encodeURI($('#textBox').val()));
});
});
</script>
Here is a jQuery demo found at jsFiddle
Here is the same thing, only it changes when you type.
If you want to use purely PHP, you need to check something has been submitted:
<form class="form-contact-warp form-calc-ship cb-form" action="" method="post">
<input class="form-control" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<input type="submit" class="btn-main-color btn-block" value="Create page" />
</form>
<?php
# Check if there is a post
if(!empty($_POST['code'])) {
# You want to make sure you remove possible html and covert the string to a url.
echo 'This is your link:<br />http://www.example.com/'.urlencode(trim(strip_tags($_POST['code'])));
}
Related
I have an HTML input and button:
<form action="validate.php" method="post">
<!-- THE CODE INSERT -->
<div id="code">
<form>
<label></label>
<input id="input" name="InputText" type="text"/>
</form>
</div>
<!-- THE BUTTON ITSELF -->
<input type="button" id="button" name="myButton"><b>Search Archive</b>
</form>
in my validate.php file I have this switch statement:
<?php
switch ($_POST["InputText"])
{
case "someval":
http_header("someaddress.com");
die();
break;
}
?>
the problem is that when I click the button it doesn't do anything. I did this with JS and it worked but it should be noted that I'm really new to web development so if anyone can explain to me what I did wrong and specifically why that would be great. Thanks!
You have a form inside of a form, that won't work. Also, you need to include an <input type="submit" value="submit" /> before you close your form. This is what submits the information from the form to your action="file.php".
A form would typically look like this:
file.html
<form action="validate.php" method="POST">
<input type="text" name="username" placeholder="Enter your username" />
<input type="submit" name="submit" value="Submit" />
</form>
Then you'd do something like this:
validate.php
<?php
echo "Your username is" . $_POST['username'];
The $_POST['username'] is the data gathered from the name="username" input from the HTML. If you write die($_POST); you'll get all the data that is sent through the form.
When you are using type='button' you have to perform the submit by yourself.
So, you can do that using javascript or change to type='submit'.
Example:
<input type="button" id="button" name="myButton"><b>Search Archive</b>
To
<input type="submit" id="button" name="myButton" value="Search Archive" />
you can try this
<form action="/validate.php" method="post">
<!-- THE CODE INSERT -->
<div id="code">
<label></label>
<input id="input" name="InputText" type="text"/>
</div>
<!-- THE BUTTON ITSELF -->
<button type="submit" id="button" name="myButton">Search Archive</button>
</form>
in the div id ="code" you used form tag that's why its not work...delete it will work and button type must be submit
how can I get users input and print it into another text field input?
I'm using php. I have 2 input types of text and one submit button. i want to be able to print the results of input A into the input textbox B
example:
<form>
<input type="text" name="input"/> <!-- thiss is where the user enters text -->
<input type="text" name="output"/> <!-- I take that text out and output it here -->
<input type="submit" value="submit" <?php echo $input;/>
</form>
I keep trying to echo "$input" into output but not working.
hope this will help
<?php
$output= (isset($_POST['submit']))?$_POST['input']:'';
?>
pure php. <br>
try to input value in input field then submit.
<form method="post">
<input type="text" name="input"/> <!-- thiss is where the user enters text -->
<input type="text" name="output" value="<?php echo $output;?>"/> <!-- I take that text out and output it here -->
<input type="submit" name="submit" value="submit">
</form>
using javascript onchange.<br>try to input value in field input1
<form method="post">
<input type="text" id="input1" name="input1" onchange="clone();"/> <!-- thiss is where the user enters text -->
<input type="text" id="output1" name="output1" /> <!-- I take that text out and output it here -->
<input type="submit" name="submit1" value="submit">
</form>
<script>
function clone()
{
var x = document.getElementById("input1").value; document.getElementById("output1").value=x;
}
</script>
You cannot do this with PHP since PHP is a server side language. It does not support client side manipulation.
You will need something like this.
<script type="text/javascript">
$(document).ready(function () {
$(document).on('change', 'input[name="input"]', function () {
var contents = $(this).val();
$('input[name="outut"]').val(contents);
})
});
</script>
<!-- HTML -->
<form method="post">
<input type="text" name="input" />
<input type="text" name="output" value="" />
<input type="submit" name="submit" value="submit">
</form>
For more information about jQuery take a look at this W3Schools article
May be this what you are looking for using simple javascript events
function myFunction(){
var a=document.getElementById('a').value;
document.getElementById('b').value= a
}
<form>
<input type="text" name="input" onkeydown="myFunction()" onkeydown="myFunction()" id="a"/> <!-- thiss is where the user enters text -->
<input type="text" name="output" id ="b"/> <!-- I take that text out and output it here -->
<input type="submit" value="submit" >
</form>
Basically I have a textbox and i want when people paste/write a website inside, and press the button, to be redirected to the site with an extra parameter ("/play/bonus")
<input name="website" id="website" type="text" />
<form method="POST" action=document.getElementById('website') & "/play/bonus">
<input name="pn" value="bonus" type="hidden">
<button id="bonus" class="btn btn-default navbar-element pull-center">
<b>50</b>
Satoshis
</button>
I would use Javascript to do this manually in code rather than making the form POST.
Here's an example for you:
<html>
<head>
<title>JavaScript Form Redirection Example</title>
<script type="text/javascript">
function goToWebsite()
{
var url = document.getElementById("inputWebsite").value;
if (url != null)
{
url += "/play/bonus";
window.location.replace(url);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="inputWebsite" placeholder="Website address"/>
<input type="button" value="Go!" onClick="goToWebsite()"/>
</form>
</body>
</html>
Very simply, what this does is make it so when the button is clicked, it runs the goToWebsite function.
The goToWebsite function:
Gets the value of the URL in the text box
Checks to make sure that the URL is not null
Adds /play/bonus to the end of it
Makes the web browser redirect to that page.
document.getElementById('website')
Will give the object of that element. You need to use .value.
document.getElementById('website').value
To get the value of element.
And there is no need to use the javascript, I think so. If you are using PHP
then use header function of PHP to redirect.
Your HTML:
<form method="POST" action="demo.php">
<input name="website" id="website" type="text" />
<input name="pn" value="bonus" type="hidden">
<input id="bonus" type="submit" class="btn btn-default navbar-element pull-center" Value="50 Satoshis">
</form>
And your demo.php file will be like this:
<?php
$redirect = $_POST['website'];
header("location:".$redirect."/play/bonus");
I have a problem with submitting a input field. I know I am not the first one who ask this question but I looked at the answers and they didn't work.
I have an input field and a submit button inside a div. I have the code working so that you can search on button press but I can't get submitting on enter press working.
html:
<div class="search singers" action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/><input class="button" type="submit" value="Search" onclick="search();"/>
<div id="output" class="output">
</div>
</div>
Jquery code:
var link = '#search';
//post input
$(function(){
$(link).keydown(function(e){
if (e.keyCode == 13) {
$(link).submit();
//He detect an enter press but stops then
}
});
});
I found the Jquery code on this site
And here a similar question: here
problem sovled I came at the idea that I have a function that makes the ajax request to send the data to php. I now call that function on enter press.
Your form should be like this. You forgot the form tag in your code, and that's why the form won't submit.
<div class="search singers">
<form name='your form' action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search"/>
</form>
<div id="output" class="output">
</div>
</div>
And second thing your autonsan function like this
<script>
function autosug() {
alert("You you are here");
}
</script>
You need to use a form. So when you will press enter, then form will be submitted including input field value.
<div class="search singers">
<form action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search" onclick="search();"/>
</form>
<div id="output" class="output">
</div>
</div>
I want to add text without reloading the page.
Here I have 2 TField (each with button POS and NEG) and 2 TArea (1 TArea POS and 1 TArea NEG).
when i input some text in first TField and then press POS button, the text added to TArea POS, and vice versa, if there is input in second TField then i hit POS, then my input append to TArea POST too.
In pure php with using FORM I could do it. but here I want page without reloading.
<div id="retrain" >
<input type="text" id="tweet" name="tweet" title="Teks retrain" />
<input type="submit" id="pos" name="pos" value="POS"/>
<input type="submit" id="neg" name="neg" value="NEG"/>
</div>
<div id="retrain" >
<input type="text" id="tweet" name="tweet" title="Teks retrain" />
<input type="submit" id="pos" name="pos" value="POS"/>
<input type="submit" id="neg" name="neg" value="NEG"/>
</div>
<div id="box" >
<textarea style="width:420px" name="posbox" rows="4" cols="70"></textarea>
<textarea style="width:420px" name="negbox" rows="4" cols="70"></textarea>
</div>
<?php
if (isset($_POST['pos'])) {
}
if (isset($_POST['neg'])) {
}
?>
Can you help my case?
Thanks for the help.
note : here i using same ID for all my input.
You cant do asynchronous requests with php. It is server compiled, not like javascript that is compiled by the browser..
learn how the internet works!
You can change fields in html with Javascript. The problem of your code is that your buttons are "submit" and thus a form has to be submitted (the page reloaded, etc). With these small changes you can get what you want:
<html>
<head>
<script>
function changeField()
{
document.form1.tweet.value=document.form0.tweet.value;
}
</script>
</head>
<form name='form0' id='form0'>
<div id="retrain" >
<input type="text" id="tweet" name="tweet" title="Teks retrain" />
<input type="submit" id="pos" name="pos" value="POS"/>
<input type="submit" id="neg" name="neg" value="NEG"/>
</div>
</form>
<form name='form1' id='form1'>
<div id="retrain" >
<input type="text" id="tweet" name="tweet" title="Teks retrain" />
<input type="submit" id="pos" name="pos" value="POS"/>
<button type="button" id="neg" name="neg" value="NEG" onclick="changeField();">NEG</button>
</div>
</form>
</html>
Logically, the only button including the new functionality is "neg" in form1: when it is clicked, the text in the "tweet" textbox above is written into the one below.