Submitting a form on a live webpage with PHP - php

I'm trying to find a way for PHP to press the "submit" button on a PHP form on a live webpage.
I need to do this as I am unsure as towards what data is send through this form, as it is a post form and the API is closed source.
Is there anyway to send a jQuery like click command to a live webpage through PHP at all?
Nothing needs to be retrieved from this form, only needs to have pressed the button correctly.
EDIT
More context:
Yes, the site is 3rd party (this is why I can't simply look up something on any API documentation), the program is downloading a gallery of images through the in-site gallery archiver. Previously the URL for this gallery's archive was stored on a simple popup window page's source. Now however you must confirm it first the page reloads (after a form submits through POST) onto the same page (archiver.php) and the download starts. This reloaded page contains the URL of the file. Nothing is submitted beyond the users confirmation to the download manually, perhaps something in the back end is sent upon this, I don't know.
EDIT 2
I've fixed this by figuring out what the form submits.

I think it is not possible to click a button on another page with php or jquery.
But you can analyse the form and find out the destination URL and send a own request. If it is GET it should look like this: myhomepage.com?id=1&name=foo&password=hello123

you have to use jQuery or javaScript For pressing submit button on live page dynamically. PHP is server side script and from is client side so its not possible. but if you want to read data from live webpage than you have to use cURL or file_get content

Related

HTML-form does not post back anymore after post with content-disposition

I don't know if it is a feature by design or something that I do wrong.
On a webpage I have a HTML-form which after a post back generates a PDF-document. This document is provided via as content-disposition. The idea was that the current page remains operation and the user can continue with its work.
But after a post back the PDF-document is provided as download, the current page stays in the browser. But the form does not post back another time.
In the form some input fields have to be filled in to be inserted in the document.
Technical order:
1) HTML form -> post
2) PHP request -> handle post and deliver PDF-document as download
3) page is browser remains the same, but does not post back anymore
Is this behavior by design or do I do something wrong in the PHP script?
Well, the problem was something of my own.
On the page a script was loaded which disabled all submit buttons after they where pressed to prevent multiple post backs.
So no weird feature of bug, but a own made problem.

create a widget using php for use on external sites

I thought it would be a great idea to let our associated dealers have the opportunity to have this on their own site as a widget. https://www.autopower.no/ ("Effektoversikt" to the right).
The "effektoversikt" fetches data from our MySQL database. Once the user finds their car and clicks "søk!" (search) they should be redirected to our page...
I'm thinking using iframe- or script-tags is the solution?
could someone point me in the right direction on where to start?
this could be a div element fed by a ajax request. The ajax request returns html snippet as search form, and when you submit, result is sent by website that generated the ajax request (so it looks like a redirect for the end user).
[edit]
Source website has an url that creates a HTML snippet as <form>...</form>. Say, not an HTML page, only the form.
target website uses, for example, JQuery to fetch the form via an Ajax request and set the html snippet into a div in target's website. As the form target is on the source website, a submit on the form automatically forward to that source site.
So create first a script/whatever that exposes the HTML snippet, then try to insert it into another page. You can experiment insertion part on JSFiddle.

detect form submission finish with jquery

As we know you cannot create a file download via ajax.
you can however submit a form which will create a download prompt.
I am generating quite a big file when the users presses a button so I display a "please wait" style message.
My question is,
How can I detect when the form submission has finished, hence the dialog box has been shown?
(this is to hide the message)
Place a redirect when form submission is successful. If redirect will hit the file which browser can't display - it will start download.
In my case I return JavaScript code from form submit handler, which form widget eval()s. That code could be a redirect to the fine which was just produced by the back-end.
Maybe my blog post about AJAX Forms best practices will be helpful:
http://agiletoolkit.org/blog/forms/
If you wish to keep things simple, then:
add form.onSubmit handler, it should prevent default action, collect form data and send to server. You can use some ajax submission plugin for jQuery.
server should parse data, prepare file and send back the name of the file to browser.
your JS code gets executed when transfer is complete (callback) and does redirect to the file through document.location.
In Agile Toolkit it would be as simple as this:
$f=$p->add('MyForm');
if($f->isSubmitted()){
$f->js()->univ()->location(prepare_file($f->getAllData()))->execute();
}
Maybe you should try something like this
http://www.iamkumaran.com/xdownloader-a-flash-javascript-library/
See the demo how file download works and I hope it may help you.

(PHP) - How do I automate passing data to a web page that uses a post action to an asp form

(php) All I want to do is execute a script where I can pass a parameter of input data that I would normally have to manually input. Its the same input data everytime so it would be nice if I could execute a script that would take me to the page and have it display the results without having to manually enter the input data each time. The problem is the input form uses a POST to a .asp form. if it helps, here is a link to the page I want to work with: http://www.msplaw.com/index.php?/Foreclosure-Sales-Records.html
thanks!!!
Wrong tool for the job. Write it in JavaScript and make it a button in your browser. Then go to the page and click the button to fill out and submit the form for you. You can make it a link you drag to your bookmarks bar in any browser, a Greasemonkey script in Firefox, an extension in Chrome, etc.

Can I have PHP redirect to an in-page link when I process a form?

I have a vertical scrolling website (lots of in-page links). I also have a contact form script I'm working on.
I'm trying to set it up so when someone completes/submits the contact form, it redirects them to #contact_area (on the same page), but calling the header function after is throwing a "Cannot modify header information" error.
Any suggestions on how to redirect after a script is processed from within ?
Thanks!
A header redirect needs to happen before PHP prints any output. If you want to direct the user to an anchor on the current page you have two options:
Submit the form as normal. Your PHP script processes the data and does this before any output: header("Location: /my_same_page#contact_area"); The page will be reloaded but they'll end up in the right spot.
Submit the form data via AJAX and then scroll to the #contact_area anchor.
The second options is probably the cleanest but the first one should be a lot easier for you to implement.
You can work around this using output buffering, few examples here
I am assuming you are posting the form back to the same right?
Maybe submit the contact form to another page for example contactus.php and once its been successful place your header location code into that OR you could use the jquery form plugin (submit() function I have used) which runs in the background and then you could maybe jquery scrollTo() your hashtag.
Go got option 1 and if you have time then play with the jquery version maybe.

Categories