detect form submission finish with jquery - php

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.

Related

Submitting a form on a live webpage with 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

How to do File upload validation Server side without refreshing the Page?

I have created a script to Upload a file using PHP. I have also added file validation checking for File size & File type. But the scenario here is, the Form contain 10-12 Text boxes & a File upload box. So whenever someone fill the complete form & submit and they get File upload validation error, they get back to the Form with the validation error message. But the form gets empty as obviously it get posted on server side.
Is there any way to do the file upload validation without reloading/refreshing the page ?
I strongly recommend this plugin for file uploads. http://malsup.com/jquery/form/
It will allow you to verify the file, and if theres an error you can use json to determine whether the file is valid or not. I use it in all my projects, it's fantastic.
EDIT: Also it allows you to submit files without page refresh, which is the most important part.
You can use ajax:
1) when submit an ajax synchrounous call send the form content to the php server page
2) the php page validates the input
3) if return is "false" (error in validation) the javascript that executed the call sympli insert into the html of the page a proper message. The form stands filled in with the values of the user
You can use $_POST array for the posted values from the form . You should have write form method as POST
Also the same way you can ajax form this will not loose any of your data and page will not refresh as well

(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.

cForms Plugin Post-Processing

I have a cForms II contact form set up. It works perfectly if I just want the results emailed to myself (default behavior).
I now have a custom PHP file that will take the POST data from the form and submit it to an external database for me. However, when I set the Alternative Form Action page to this PHP page, clicking the Submit button just causes the form to hang.
How exactly do I pass the form data to my own PHP file while still keeping AJAX enabled (so form validation works)?
Cheers!
Ah, I figured it out!
To do post-processing, you don't redirect the form submission to your own file.
You simply modify the my_cforms_ajax_filter($params) function in the my-functions.php file (in your cForms directory).
This function is executed after form validation and before any data processing takes place (so you can intercept the form data).

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