As @Leonardogetulio said, n ways to do this, I’ll give an example of how to do this through ajax:
Your HTML on the site a:
<!DOCTYPE html>
<html>
<head>
<title>Site 1</title>
</head>
<body>
<form method="POST">
<label>Texto</label>
<input type="text" id="texto" name="texto">
<button class="btn btn-sucess" id="send">Gravar</button>
</form>
</body>
</html>
The javascript:
<script>
document.addEventListener("DOMContentLoaded", function(event) {
//depois que o dom for lido
function processRequest() {
//AQUI VOCÊ RECEBE OS DADOS DO SITE DOIS
if (xhr.readyState == 4) {
if (xhr.status == 200) {
//sucesso, você obterá retorno de um JSON com dados
console.log(xhr)
}else {
//erro, vc obterá retorno de um JSON com erros
console.log(xhr)
}
}
}
var button = document.getElementById('send'),
input_text = document.querySelector('#texto'),
actionSend = function() {
//ENVIA PARA O SITE DOIS
var url = 'http://www.sitedois.com.br/index.php',
dados = {
texto: input_text.value;
};
var xhr = new XMLHttpRequest();
if (xhr.withCredentials !== undefined) {
/* AQUI VOCÊ PROVAVELMENTE VAI PRECISAR
VALIDAR AS CREDENCIAIS ENVIANDO NO HEADER
O QUE O SITE PEDE PARA PODER LIBERAR O DADO */
//xhr.setRequestHeader("PARAMETROS","VALORES");
}
var randomNum = Math.round(Math.random() * 10000);
xhr.open("POST", url + '?rnd='+randomNum, false);
xhr.send(JSON.stringify(dados));
xhr.addEventListener("readystatechange", processRequest, false);
}
xhr.addEventListener("readystatechange", processRequest, false);
button.addEventListener("click", actionSend, false);
});
</script>
<form method="POST" action="index.php">
I think you want to put the form action, that’s it. Or you want it in ajax?– Ivan Ferrer
Yes, but the form data is on site 1, have to go to site 2, the action serves for other sites as well?
– Victor Stanford
There is a rule of security for each site, what you want to do is basically Restful, use an API, one site and publish in another, first you need to have access to both properties of the sites, or have a CORS access, and to do so, only using ajax.
– Ivan Ferrer