+1 vote
by
Chrome works as I need, first sends the form and then leaves onClick, but from the phone form is not sent, immediately redirect. How do I fix it?
<table border="0" width="100%" id="table1" cellspacing="1" cellpadding="2">
<br>
<tr><b>ВАШ ТЕКСТ</b><font color="red">*</font>:<br>
<textarea rows="7" name="f3" cols="30" style="width:50%;"></textarea></tr>
<tr><td colspan="2" align="center"><input type="submit"
value="Отправить СООБЩЕНИЕ" onClick='location.href="ССЫЛКА НА СТОРОННИЙ РЕСУРС"'></td></tr>
</table>
by
Show the form in its entirety, with the tag<form></form> inclusive.
by
And why are you doing it on the client side:
onClick='location.href="ССЫЛКА НА СТОРОННИЙ РЕСУРС"'

And not on the server side after processing the form data?
header('location: ССЫЛКА НА СТОРОННИЙ РЕСУРС');
by
alexalexes I can't change something on the server, I need to do this processing on the client side.
by
alexalexes , it's ucoz
by
oleg_berezovskyi I would show you, but you stubbornly do not want to put all the html code of the form.
by
alexalexes , can I have a link to similar information, what does it look like approximately?
by
Then you don't have to submit the form, but write a separate js-script to form the formData object and send it by ajax, and after that location.href="LINK TO SIDE RESOURCE".
And so, there will be competing handlers, depending on how you decide to write the browser, either by submitting or by your href.
by
oleg_berezovskyi , give me a link to the page then.
by
Nadim Zakirov The thing is that on ucoz this is all I have
<table border="0" width="100%" id="table1" cellspacing="1" cellpadding="2">
<tr><input maxlength="70" name="f1" size="30" style="width:95%;" type="hidden" value="BAZA@RF.RU" /></td></tr>
<tr><input maxlength="70" name="f2" size="30" style="width:95%;" type="hidden" value="ТЕМА" /> </td></tr>
<br>
<tr><b>СООБЩЕНИЕ</b><font color="red">*</font>:<br><textarea rows="7" name="f3" cols="30" style="width:50%;"></textarea></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Отправить" onClick='location.href="Ресурс для редиректа"'></td></tr>
</table>
by
Replace the submit button with an ordinary button that calls a handler with code like this.
https://developer.mozilla.org/ru/docs/Web/API/Form...
by
Please, but adapt it yourself.
var formData = new FormData();
// Таким способом вы снабдите объект нужными данными
formData.append("username", "Groucho");
formData.append("accountnum", 123456); // число 123456 немедленно преобразуется в строку "123456"
// Так его отправите
var request = new XMLHttpRequest();
request.open("POST", "http://foo.com/submitform.php");
request.send(formData);
// А так средиректите
location.href="ССЫЛКА НА СТОРОННИЙ РЕСУРС";
by
alexalexes UCOZ bit me for this code) It says invalid content)
by
alexalexes , you can code it, I'm totally lost there
by
alexalexes , this triggers a redirect

<script type="text/javascript">
$( "form" ).submit(function( event ) {
2
window.location.href="ССылка";
3
event.preventDefault();
4
});
</script>
Can I just do a delay in step number 2, if so, how?
by
FanatPHP , be complacent. Not everyone can understand the scope of the problem to give the necessary set of tags.
oleg_berezovskyi how do you use this code?
by
Now I just need to know what RNR has to do with it
by
Is it possible to change the button type to this?
<input type="button" value="Отправить" onClick=''>
by
alexalexes it only allows me to embed in the same window as the form, but as soon as I open the page with the form I get redirected at once
by
What is ukoz fighting about?
To create an object:
var formData = new FormData();
or
var request = new XMLHttpRequest();
by
How do you do it?
by
alexalexes I prescribe a button and it becomes inactive
by
How about this?
Notice request.open("here you need to specify the same send method as in the form", "here the same action as in the form");
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("input[name='f3']").value);
var request = new XMLHttpRequest();
var this_form = event.target;
var form_method = this_form.getAttribute('method');
var form_action = this_form.getAttribute('action');
request.open(form_method, form_action);
request.send(formData);
window.location.href="ССылка";
});
by
alexalexes , Yes, but in this form it redirects without sending the form
by
In this composition gives to save the code?
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
var request = new XMLHttpRequest();
window.location.href="ССылка";
});
by
alexalexes This is what I have in the code now,
<script type="text/javascript">
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("input[name='f3']").value);
var request = new XMLHttpRequest();
var this_form = event.target;
var form_method = this_form.getAttribute('method');
var form_action = this_form.getAttribute('action');
request.open(form_method, form_action);
request.send(formData);
window.location.href="ССылка";
});</script>


<table border="0" width="100%" id="table1" cellspacing="1" cellpadding="2">
<tr><input maxlength="70" name="f1" size="30" style="width:95%;" type="hidden" value="BAZA@RF.RU" /></td></tr>
<tr><input maxlength="70" name="f2" size="30" style="width:95%;" type="hidden" value="ВАША МЫСЛЬ" /> </td></tr>
<br>
<tr><b>Ваш текст?</b><font color="red">*</font>:<br><textarea rows="7" name="f3" cols="30" style="width:50%;"></textarea></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Отправить" ></td></tr>
</table>
I have no idea how to determine method and action
by
method="post", but the action is not, so it is the same url as the current page.
Try it:
<script type="text/javascript">
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("input[name='f3']").value);
var request = new XMLHttpRequest();
request.open('POST', 'http://mydape.ru');
request.send(formData);
window.location.href="ССылка";
});</script>
by
I won't ask you what you dug up in the Elements tab on the form.
This code should retrieve the desired properties from the form, I corrected the message above with this part in mind.
var this_form = event.target;
var form_method = this_form.getAttribute('method');
var form_action = this_form.getAttribute('action');
request.open(form_method, form_action);
by
It seems to be working.
by
Your f3 is a textarea, so it is:
<script type="text/javascript">
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("textarea[name='f3']").value);
var request = new XMLHttpRequest();
request.open('POST', 'http://mydape.ru');
request.send(formData);
window.location.href="https://google.com"; // перенаправляем на гугль.
});</script>
by
alexalexes , there is no redirect
by
alexalexes , From the phone does not work, only a PC
by
alexalexes , there is a redirect, from the PC form is sent from the phone does not have time
by
Did the message catch on?
by
It would be more correct to do it through the response handler:
Try to use:
request.onload = function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
};
I posted the answer. Mark it as a solution. PS: note that send is called at the very end. PSS: Don't abuse the likes in the comments.
by
Then do a redirect delayed:
setTimeout(function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
}, 3000);
by
alexalexes , Finally WOOOOOOOOAAAAAAAAAAAAAAAAAAAAA. Thank you so much.

1 Answer

0 votes
by
 
Best answer
<script type="text/javascript">
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("textarea[name='f3']").value);
var request = new XMLHttpRequest();
request.open('POST', 'http://mydape.ru');
request.onload = function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
};
request.send(formData);
});
</script>
...