How to submit a form to download a page without clicking the submit button?

Is there a way to make the submit "onload" form without clicking the send button with PHP button? I saw some ways to do this using Javascript, but I love php and id to do this using php.

For instance:

<form action="https://xxxxxx.com/yyy.php" method="post" id="foo"> <input type="hidden" name="LoginEmail" value="user [at] domain.com"> <input type="hidden" name="LoginPassword" value="mycleartextpassword"> <input type="submit" name="Authenticate" value="Login"> <input type="hidden" name="Action" value="1" > </form> 

I can do this with javascript:

 <form id="foo"> .... < /form> <script type="text/javascript"> function myfunc () { var frm = document.getElementById("foo"); frm.submit(); } window.onload = myfunc; </script> 

Well, can we do the same with PHP? Could you kindly share your ideas and tips?

Thanks.

+4
source share
5 answers

It is not possible to complete the form submission action on the client side (i.e.: browser-based) using the server language (i.e.: PHP). This is like trying to get a library to read a book, if that makes sense. (You get books from the library and return them there, but the library itself cannot read books.)

Thus, JavaScript is your only solution if you need automatic submission. Even then you need to provide a “normal” solution for use by people who do not have JavaScript enabled. (The joy of graceful degradation, etc.)

+4
source

I had a diffculty in dong it also thought so that i will post my solution here, it goes ...

this curl command sends the file to the url and sends back whatever data it receives. It sends an xml file, so the content type is set to application / x-www-form-urlencoded. Api, I sent a request for the data to be encoded, so I use --data-urlencode. I also assign a file name with the variable name to the post here, so it seems to send an input field with name = "whatever."

 curl --data-urlencode [post variable name] =@ [filename] --header "Content-Type:application/x-www-form-urlencoded" http://[url to send file to] 

Assigning a command to a variable is easy ... see below

 content=$(put curl command in here); 

P. DO NOT FORGET TO CHOOSE ANY '=' or '&' in your URL, this causes problems if you try to get the data.

+2
source

If you want to automatically submit the form after the page loads (IMHO this is pointless), I assume that you created your values ​​yourself (using the PHP code) and you want to submit them to another page, right? If so, redirect the page to another by title (), passing values ​​through POST:

 $post_data = 'LoginEmail=username [at] domain.com&LoginPassword=...'; $content_length = strlen($post_data); header('POST /another_page.php HTTP/1.1'); header('Host: fancyhost'); header('Connection: close'); header('Content-type: application/x-www-form-urlencoded'); header('Content-length: ' . $content_length); header(''); header($post_data); exit(); 
+1
source

this is using jquery ajax.

 $(document).ready(function(){..........your code goes here........}); 

if you prefer jquery replay me i will give you help

0
source

Use printf to print your javascript code, then when the client browser receives the page, it will execute your javascript.

 printf("<script type="text/javascript"> function myfunc () { var frm = document.getElementById("foo"); frm.submit(); } window.onload = myfunc; </script>"); 

I do this a lot for map services.

0
source

Source: https://habr.com/ru/post/1336131/


All Articles