If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Ways to remain on the webpage after submitting the form?

Started by Ankan, Apr 14, 2023, 12:06 AM

Previous topic - Next topic

AnkanTopic starter

The form is located in Domain 1, and upon submission, it redirects to Domain 2 and provides a success response.
Is it feasible to remain on Domain 1 after submitting the form without modifying or downloading the script to your host, taking into account that the user lacks control over Domain 2?

Here is the form code:

<form method="POST" action="Another_Domain.dll/do_it">
         Please enter your phone number:
         <input type="text" name="phone" maxlength="32" size="16">
         <input class="button" type="submit" value="Call">
</form>
  •  

kr1e

Is it necessary for you to receive a response from the second server? If not, utilize the target="FRAME_NAME" attribute for the form, establish an unpopulated and unnamed frame on the page, and designate its name in the form.

In the event that the response from the child site is crucial, the only available option is to proxy through your own server. Essentially, you send an AJAX request to your server, which then forwards it to the second server via curl. Your server will receive a response and send it back to your page.
  •  

ttradexs

Use ajax to transmit data, and once a success response is received, use javascript to display something on the screen, such as an alert.
Consider utilizing jQuery Form, which I used to upload files without refreshing the page, but be aware that you may encounter difficulties with CORS.
  •  

Mycrib

The easiest and oldest choice for your circumstance would be PHP.

When the request method is 'POST', the code sets variables for name, family name, email, and comment using the user input from a form. The header function redirects the user back to the previous page, and the exit() function terminates the script.

if($_SERVER['REQUEST_METHOD'] == 'POST') {
     $name = $_POST['name'];
     $familyname = $_POST['familyname'];
     $email = $_POST['email'];
     $comment = $_POST['comment'];
     header('location: ' . $_SERVER['HTTP_REFERER']); // or explicitly specify the path to the form
     exit();
}
  •  

jyotisharma

No, it is not feasible to remain on Domain 1 after submitting the form without modifying or downloading the script to your host. Once the form is submitted and the action attribute points to a different domain (Domain 2 in this case), the browser will redirect to that domain upon submission. Users do not have control over this behavior, as it is determined by the form's action attribute.

To elaborate further, when a form is submitted, the browser sends an HTTP POST request to the URL specified in the form's action attribute. In your case, the action attribute is set to "Another_Domain.dll/do_it", which means the browser will send the request to that specific URL on Domain 2.

The server at Domain 2 will process the request and send back a response. It is up to the server to determine what response to send back, such as a success message or an error message.

After the response is received, the browser typically follows the instructions provided in the response. In most cases, this involves a redirect to a different page or URL, specified in the response headers or body. This is how the user ends up on Domain 2 after submitting the form.

If you want to stay on Domain 1 after submitting the form, you would need to modify the server-side code on Domain 2 to handle the request differently. For example, instead of redirecting, you could return a response that includes JavaScript code to update the current page on Domain 1. However, this would require access and control over the server-side code on Domain 2.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...