How to fill a textbox of another domain, from my domain? [duplicate] - javascript

This question already exists:
How to send data from Domain 1 input type='text' to Domain 2 input type='text' [closed]
Closed 8 years ago.
How can i insert a value to another domain (not have access to this domain) textbox, from filling a form from my domain?
Form in my domain:
<form action="" method="post" name="birthdaysend">
<input type="text" value="" name="birthday" >
<input type="submit" value="submit">
</form>
Where this value will be shown in the other domain textbox (where i do not have access)
<form action="" method="post" name="birthdayreceive">
<input type="text" value="" name="birthdaydate" >
<input type="submit" value="submit">
</form>
When i fill birthday date from my form, on submit the same date to be shown in this other textbox where i do not have access.

Imagine the other domain is your visitor's online banking and that the text box is where you put the account number to transfer money to.
Now, for obvious security reasons, what you want it entirely impossible.

After you received your own form from your server, you need to mimic a browser to request the page from other domain, and submit that form using your own code.
One example I think is cURL extension
PHP can post data to other domains by using the cURL extension

On form submit, you could get a $_GET or turn the $_POST into a $_GET,
Send the $_GET to another domain like
www.otherdomain.com/index.php?textbox=
then from the textbox on the other domain
<textarea><?php echo $_GET['textbox']; ?></textarea>
or
<input type="text" name="name" value="<?php echo $_GET['textbox']; ?>" />
Im not really for sure what your trying to accomplish, I hope this gives you and idea to what exactly im getting at here. Or my other result is to use cURL, so the other domain can get the information from the other server.

Related

Trying to access the value of a text field in PHP before submitting the form

I am trying to access text entered by user in a text field even before submitting the form. For this, I am thinking to adding a click event on 'Submit' button to access the value of text field using Jquery. But, I am not sure how to assign it back to a PHP variable.
Can someone help?
<form action="">
<input type="text" name="inputs1" class="inputs1" placeholder="Enter the name" required>
<input type="button" class="submit-btn" name="submit" value="Submit">
</form>
<?php $variable = ? //value of input field name ?>
php is a server-side scripting language. so you cant really assign a value to php variable until a request is sent for the server to process i.e. form is submitted
With PHP, you can't until you submit the form. Instead you can do this with Javascript.

How to prevent a form from opening action url and only print when submitted?

i am building a form and when i submit it it opens the action url. I want to submit the form on click button which should not open the target url but submit the request. as well as i want to print a message after submit and form should be cleared after submit.
<form id="contact" action="https://control.msg91.com/api/sendhttp.php" method="post">
<h3>Send SMS</h3>
<h4>Build in Process</h4>
<fieldset>
<input name="authkey" type="hidden" value="auth key as required"/>
<input name="mobiles" placeholder="Mobile Number" type="text" tabindex="1" maxlength="10" required >
</fieldset>
<fieldset>
<textarea name="message" placeholder="Type your message here...." tabindex="2" maxlength="320" required></textarea>
</fieldset>
<input name="sender" type="hidden" value="FAKEin" />
<input name="route" type="hidden" value="4" />
<input name="country" type="hidden" value="0" />
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
</fieldset>
</form>
any help how can i do this?
also can i add a hidden text in message tab that should add to the message tab in post/get as + instead of &
eg. actionurl.php?authkey=custommade&mobiles=9999999999&message=orginal+message+hidden+message&sender=FAKEin&route=4&country=0&submit=
You can also check the source code of page https://www.tricksbygoogle.com/sms/sms.php
Basically You can't .
The only solution here I see , is using ajax query and use javascript to clear form.
This example I provide is no redirections at all. What means you page will not be reloaded.
Maybe little jquery will help.
var result_func = function(response){
if(response.allOk){
$this.reset();
}
}
$('#contact').submit(function(e){
e.preventDefault()l
var $this = $(this);
var data = $this.serialize();
$.post($this.attr('action'),data,result_func.bind($this));
});
Header location will work , but user still will be redirected.
Based on your question, and the comments it looks like you're going to have to do a little bit of research. Here are some tips though.
If you would like to include the functions from a page without actually visiting the page, than you can use what is called an include statement. This will keep the browser from visiting that page while still executing it. - http://php.net/manual/en/function.include.php
To display a message you're going to need to hide and show the element with javascript. I would suggest viewing this question - Hide div after a few seconds
Basically on submit, you're going to want to check for the variables from your form. You would run a php if statement.
Then, if those variables exist you are going to want to include your action page.
In the same if statement, you're going to want to echo a <div> with a class that has some javascript attached to it to hide it after a few seconds.
The form will automatically clear on submit.
if($variable != null){
include '/action.php' // --- you can add some GET variables to the end of this if you would like to.
echo '<div id="message">Message sent</div>'
}

Send text field value using href to php

I have to send text field value using href to php is something like below. But it is not correct way. Can anyone please give me any solution?
<input type="text" id="myText" value="Mickey">
<a href="test.php?id=javascript:document.getElementById('myText').value;">
<input type="button" value="Click"></a>
Put content inside a form. You can also change the button type input to a submit type, this way the form is sent automatically on click.
<form method="POST" action="yourURL.php">
<input type="text" id="myText" name="myElement" value="Mickey">
<a href="test.php?id=javascript:document.getElementById('myText').value;">
<input type="submit" value="Click"></a>
</form>
More information on forms: MDN
Whether you use GET or POST as a method, you'll be able to access the content of the form through PHP variables: $_GET, $_POST or the generic $_REQUEST.
More information in the PHP documentation
Note: PHP uses the name attribute of your HTML elements for those variables. Make sure to add this attribute to your HTML elements otherwise you'll have a hard time getting a value from $_REQUEST['myText']. I added the attribute holding the value "myElement" in the above code. It is accessible through PHP by typing $_REQUEST['myElement'].
Content sent through GET method is visible in the URL,
like this: www.example.com/test.php?var1=test&var2=test
<input type="text" id="myText" value="Mickey">
test

Submit form method=post with multiple different value=xxx with similar name=x?

I need to retype a bunch of names written on a paper and make a digital copy of it to a computer (a txt file). Then copy/paste each name and submit it again into a website one by one. Type one name then submit, wait until the page reloads, then repeat again. I saved the html file of the website but I don't have access to website's server. I was thinking I could modify the html file I saved so I'll just copy/paste once then click submit once. I'm not sure if it's possible to copy the names from the text file and embed it in the html code or maybe make a code to read the names from the txt file.
Honestly, I don't mind copy and pasting the names one by one into the website. What slows me down is the page reload time and the website only has one input field. It takes a few seconds to reload after submitting one name. So I want to be able to copy paste all then submit it once. I saved a local copy of the html file of the website and added action="website.com/xxxx" so it submits it to the website even if the html file is saved on my computer. The code below is a part of the website's html code:
<form method="post" action="website.com/xxxx">
<input type="text" name="t" style="width:250px">
<button type="submit"><p>Submit<img src="submit.png" style="width:32px;vertical-align:middle"></p></button>
</form>
I was thinking if I could modify it like this:
<form method="post" action="website.com/xxxx">
<input type="text" name="t" style="width:250px" value="jane">
<input type="text" name="t" style="width:250px" value="jenny">
<input type="text" name="t" style="width:250px" value="mark">
<input type="text" name="t" style="width:250px" value="ben">
<input type="text" name="t" style="width:250px" value="cathy">
<button type="submit"><p>Submit<img src="submit.png" style="width:32px;vertical-align:middle"></p></button>
</form>
If you have PHP with HttpRequest installed, you can try something like this
<?php
$url = 'http://website.com/xxxx'; // url of the form action, not the form itself
$names = file('names.txt');
for($names as $name){
$request = new HttpRequest($url, HTTP_METH_POST);
$request->addPostFields(array('t' => trim($name)));
$request->send();
}
If you have PHP but no HttpRequets, you can use cURL, but I have absolutely no idea how it is working.
Other languages should have similar possibilities.

Extracting data with PHP

Helo friends, my code:
<form>
<input type="text" placeholder="name">
<input type="text" placeholder="email">
<input type="password" placeholder="pw">
<button type="button" id="insert">Insert</button>
</form>
My JavaScript file:
$('#CadAdmin').click(function(){
$('input').each(function(){
$.post('/require/jp/insert.php',{
dataUser:$(this).val()
},function(res){
alert(res);
})
})
});
My insert.php file:
extract($_POST);
print dataUser;
Here, its show all data, ok but, I want to get separete data, for ex:
//print dataUser
print $name.' '.$email.' '.$pw;
The $_POST variable is an array (see $_POST on php.net). This means you can access the inner content like this $_POST['index'].
For you this would mean that you have to use the form input names with $_POST. This gives you $_POST['name'], $_POST['email'] and $_POST['pw']. These variables contain the input from the form.
Note that just printing/echoing these variables to your website you might have some problems with XSS, you can check this answer or this one (both from other questions) for on how to prevent something like that from happening.
EDIT (after comment):
I suggest you to change (or even remove) your javascript code. Because you are using $('input').each() you are currently sending 3 separate POST requests to /require/jp/insert.php, this means the data is handled separately. If you were to change that, your inputs do not have a name, that is why extract() doesn't work, the data within $_POSTisn't set to a specific 'variable' to use after extract().
I suggest you change your code to something like this:
(somehtmlpage.html?):
<form method="POST" action="/require/jp/insert.php">
<input type="text" name="name" placeholder="name">
<input type="text" name="email" placeholder="email">
<input type="password" name="pw" placeholder="pw">
<input type="submit" id="insert">Insert</input>
</form>
(insert.php):
extract($_POST);
print $name.' '.$email.' '.$pw;
What this does is exact the same, without javascript (and the 3 POSTs). Since your data is now within the 'same' $_POST you can use the names (from the input fields, 'name=....') after extraction.
You need to define the name (not the placeholder) of each input, then serialize the form data before posting it to your insert.php script.
First, add name attribute to your elements to catch their values after form submit:
<input type="text" placeholder="name" name="name">
then you can get those values like this:
$name = $_POST['name'];

Categories

Resources