I have a page and a large form with many texareas (lot of text, I've made a cms system) and my form is kinda "heavy", I use some javascript to update it and then save/post form with php submit and $_POST variables and that bit.
I have given this javascript function a setTimeout to 3 seconds to give the form some time to update before saving, just to be safe. This halts the save function and makes everything slower of course, which is a little annoying and not so smooth.
Is this neccessary ? I really dont want my users to get half the form saved if I dont have the timeout before saving (i.e. if the machine running the page is slow).

The save/post commando is executed at the end of the update javascript function. Javascript do one line at the time at executing the code, right ?
It wont save before update is done if the save command is at the end ? or am I wrong ?
(I've done some c++ programming before and threads were executed at the same time if not using callbacks.)

Done some debugging to check this, but am I just being too scared and careful ?
Can I leave out the timeout ? Is speed an issue ?
Sorry many questions, any thoughts?
thx!

Member Avatar for diafol

I don't understand what you mean by updating the contents. Does the js alter the user input before the form is sent? Is this a validation routine?

sorry. yes the js alters the textarea before form is sent.
the textarea's are hidden and text are "dumped" into them from input fields, and then page and form is sent/submitted.
the value of the textarea is then being saved to a file, which is then included in other pages as part of source code.

Member Avatar for diafol

Are you sure that this is required? Copying to a hidden widget seems unnecessary to me. If you've got input widgets, they'll be sent to the server anyway won't they? Well, unless they're outside the form tag containing the submit button. Wouldn't it be easier (and faster) to send all the data to php to go the reformatting/re-jiggling?

The problem is that this cms app I've made is incredibly dynamic and I found that the easiest way to do things is to dump all in hidden widgets after formatting and all that, and also my js-skills is far greater than my php-skills, so doing formatting and all that is easier on the client-side for me, although I think it would be faster on the server side. I'm still learning php, and found it to be an easy way to save files, something that js can't do as easy, although it has got xmlhttprequests and that bit. So I always end up with some dirty hacking to get things done. I wish I didn't have to.

Member Avatar for diafol

I think that using php to alter the input would be a more robust method. You can still use the ajax object for form submission, but you just don't mess with js for re-formatting. Seriously, I would suggest you spend some time developing a php-only solution to this - any text reformatting/re-jigging you do with js, you can do with php. This would mean NO HACKS.

yes I agree with you, and I'm in digging deeper into php every day and learning more, it's just that when I know how to do something with one language I tend to use it, I feel php is a harder to debug and test, either it works or nothing happens at runtime, maybe an odd errormessage now and then, guess I havent found the right editor, now using Dreamweaver CS3 for all my html,css,js,php developing (everything in codeview of course) but it has it's limitations. Havent found any good all round editors, seen some php editors but they all seem to lack something.
Guess I'll just have to keep on learning more, and stop hacking.
Thanx!

Member Avatar for diafol

Gotta admit, I still use Dreamweaver from time to time. I sometimes use Notepad++, Aptana, Netbeans and Eclipse - depends on the project. They're all free/open source.

Here's a screenshot of Eclipse - note the php debug button.

ok, thanx I'll check it out
:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.