Page 1 of 1

event after form submit completion?

Posted: Thu Apr 26, 2012 10:11 pm
by wvoyance
Is there any such event that can do something after the form submit is finished?
Thanks. :roll:

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 12:36 am
by requinix
What do you mean by "finished"?

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 1:42 am
by wvoyance
requinix wrote:What do you mean by "finished"?
:cry: That become philosophical ? ......any similar will help.
onAfterSubmit ? onCompletion ? :mrgreen:

I have a form which insert a book information into database, but not the image.
The image is copied into the directory. Only after the book record is created I can insert the image into that record.
Therefore, I need to do something onCOmpletion :lol: :lol:

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 1:50 am
by requinix
Okay... How about this: does submitting the form reload the page?

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 2:35 am
by wvoyance
requinix wrote:Okay... How about this: does submitting the form reload the page?
yes, reload.
So, you suggest to use onreload? But that might happen at other condition.

Could I put the function just after the table?

<table...>

</table>
function to be excuted on completion;

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 3:14 am
by requinix
There is no such thing as an "onreload" event.
You can't have code on one page affect a later page. It's a pretty fundamental concept in JavaScript. So much so that I've never even seen it stated anywhere.

So the form allows for creating book records. Why not have the image upload there too and only run that code once the book has been created?

Code: Select all

<?php

if (form was submitted) {
    insert new book record;
    add the image to the record;
    etc;
}
Also, and I'm just taking a guess here, but I bet your "only after the book record is created" statement isn't quite true. I bet you could do it at the same time, or with one or two statements immediately after.

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 4:07 am
by wvoyance
You asked a good question! :banghead:

Perhaps I did something stupid.
The code was part of OSCommerce, which you might know.
Let me post them
http://pastebin.com/uGddv7wZ
This is the categories.php which administrator need to fill the form and put the products to the shop.
However, I want to built a book store which need at least 100000 products, cannot put by hand.

Therefore I wrote a program the administrator only need to enter ISBN (products number) and price.
The program will get other information (title, author...etc) from other libraries, and the products image.
The problem is products information is text while image is jpg file.
They are handled differently.
I used javascript AJAX call to server to send_one_isbn.php
http://pastebin.com/afB49Zya
This program copy the image and other information.
The "other information" is transmitted back the fill out the form, but image cannot.
Firstly, I don't know how to transmit image file back. Secondly, even if it it back,
<input type='file' will have difficult to set the value.
So, I insert the image directly into the database by another php program add_image.php
http://pastebin.com/jnWuRtdn
But the other part of the form are uploaded separately.
The insertion of the image need to wait till the other part of the form inserted.
...............
so....I got this problem......

Re: event after form submit completion?

Posted: Fri Apr 27, 2012 5:12 pm
by requinix
Don't do it all in JavaScript. Feel free to write some PHP code to do work.

You can "forge" form information pretty easily with code like

Code: Select all

<?php

// set up fake form values
$_POST["field1"] = "value";
$_POST["field2"] = "value";

ob_start(); // start output buffering so output isn't sent to the browser
include "original_file.php";
ob_end_clean(); // discard everything
There are a couple potential problems though: functions like is_uploaded_file() require files that were actually just now uploaded, and exit; and die; will completely stop everything.