Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nagraj722's avatar

Redirect to external url with form data from controller

I need submit a form to external website from the controller and method should be POST. can anyone help me.

I have tried below code but not succeed.

Redirect::to('https://externalwebsite.com/page.php')->withInputs($request->all());

Thanks,

0 likes
4 replies
tisuchi's avatar

You are trying to merge redirect and form submission, that is not the same.

You may submit form data to the external website if they have API.

1 like
Nagraj722's avatar

@TISUCHI - Thanks @tisuchi, The external web site is not an API. Actually, I need to store form data on two websites one is mine another is different. First, I'm stored data on my website than trying to send form data to the external site. can anyone suggest me any alternative solution for this.

tisuchi's avatar

What I have in my mind is to add by manipulating DOM that is somehow related with JS.

Nagraj722's avatar

I have done wit js

    var url = "{{ url('contactus') }}";
      function OnButton1(){
        document.contactus_form.action ="https://externalsite/page.php";
          document.contactus_form.submit();      
        setTimeout(function(){
        

        document.contactus_form.action = url;
        document.contactus_form.submit();  
        },200);
      }

here im using setTimeout function, it's working but sometimes not working due to the server load time. that's why im searchin another solution i.e, submit second action from controller.

Please or to participate in this conversation.