b

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
boujin
Forum Newbie
Posts: 8
Joined: Sat Feb 11, 2006 4:52 am

b

Post by boujin »

gjghjg
Last edited by boujin on Tue May 23, 2006 2:35 pm, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Actually, the posting of a form happens at client-side... Thus you really need code for a client-side engine...

If you want to post a form at server-side you'd probably use something like curl, simpletest browser, ...
boujin
Forum Newbie
Posts: 8
Joined: Sat Feb 11, 2006 4:52 am

Post by boujin »

ghfghf
Last edited by boujin on Tue May 23, 2006 2:35 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

No. Javascript is read by the client (like HTML) and parsed at the client's end.

If you have Javascript disabled it won't work, doesn't matter how you send it to the client.

Server-side languages such as PHP are parsed on the server and then the output is sent to the client.

Edit: I beat feyd, wooooooooooo.
Last edited by jayshields on Sat May 20, 2006 9:25 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The Javascript isn't run serverside, so no it won't work if Javascript is disabled.

I see no reason to keep the Javascript posted.
boujin
Forum Newbie
Posts: 8
Joined: Sat Feb 11, 2006 4:52 am

Post by boujin »

fghfghf
Last edited by boujin on Tue May 23, 2006 2:37 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

boujin wrote:So what code could I use to substitute this javascript?
All that this javascript does is submits a form. I'm struggling to see a purpose in doing that server-side, unless you're trying to complete forms on other sites from your PHP scripts?

In which case you need cURL to send POST data to the other server. Perhaps some reading up on the HTTP protocol and the 2-tier architecture would be a help:

http://en.wikipedia.org/wiki/Client/ser ... chitecture
http://en.wikipedia.org/wiki/Http#Request_methods
http://en.wikipedia.org/wiki/Http#Sample

You basically are trying to send a HTTP POST request to a server.
boujin
Forum Newbie
Posts: 8
Joined: Sat Feb 11, 2006 4:52 am

Post by boujin »

dfgdgd
Last edited by boujin on Tue May 23, 2006 2:36 pm, edited 2 times in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

boujin wrote:I have a 100% javascript shopping cart on my web. I have had many clients complain because they had problems with it (they weren't able to "checkout" and buy on my site). I acknowledge that a percentage of them could be scams but I am sure that this was the case with many of them. My best guess is because it is made with javascript (probably because some clients have part/all of javascript disabled on their browser).

So I bought a cart made in 100% PHP (server side) but it has this only javascript code in it. So here I am trying to find a way to substitute this only javascript with some other server side language. I must say that I have basically no idea of javascript nor php (I see both very complicated) but I do have quite a good knowledge of xhtml (very easy to understand).

Apparently the javascript does this:

"calTax is a simple little function that gets called when the user selects a state; that function then re-submits the whole form back to hello.php with the state info so it can determine the tax status..."

Is there any way to make this function server side or maybe you need more information?
I think we need to think about what we're trying to acheive a little better here ;)

So far we know, the js we have here submits the form (client-side)
It executes when the user changes the state (client-side, 100% non-avoidable)
It sends data back to hello.php (presumably to recalculate tax?)

So the problem here: There's a level of user input involved which of course happens on the clinet's computer.

If you want to remove the javascript go ahead, you'll just need to place a little "Update" button (which is just another <input type="submit">) right next to the part in the form where the user changes the state.

Personally I'd keep the javascript and just add the update button (maybe even in a <noscript> tag) to the form. This way if the user has JavaScript they will get an enhanced experience with the form, otherwise they'll just have an extra click to make.

To summarise, you can't have the server respond to user input without something happen on the client-side.

Good luck :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If i understand it right, somewhere there is a event that calls the calTax() function...

If you simply add a <input type='submit' ... /> button to your form you can let the users post their data...
Post Reply