Welcome to WebmasterWorld Guest from 54.205.119.93

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Retrieving a javascript value and creating a PHP variable?

I'd like to pass (this.form.orderdate.value) as a $_POST variable...?

   
4:35 pm on Apr 23, 2010 (gmt 0)

10+ Year Member



I use a javascript file to display a calendar and allow me to select a date. The date is formatted to the SQL format - but is represented as (this.form.orderdate.value) ... so how would I go about turning (this.form.orderdate.value) into a variable in PHP? I'm sure this is terribly simple but I haven't come across it in any of my books or websites...

Thank you very much!
4:47 pm on Apr 23, 2010 (gmt 0)

5+ Year Member



To convert the JavaScript variable to a PHP variable, you need to send the variable to the server, like you would either through a QUERY or a POST.

To do this, your onClickDate method would include a line like:
location = "?orderdate=' + this.form.orderdate.value + "'";

Or

this.form.action = ""
this.form.method = "POST"
this.form.submit();


Your PHP code then would execute the following:
if (isset ($_REQUEST ['orderdate'])) { orderdate = $_REQUEST ['orderdate']; }

Hope this helps

E Net Arch
4:48 pm on Apr 23, 2010 (gmt 0)

5+ Year Member



correction ...
location = "?orderdate='" + this.form.orderdate.value + "'";
4:58 pm on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi all,

if (isset ($_REQUEST ['orderdate'])) { $orderdate = $_REQUEST ['orderdate']; }


Apart from missing the dollar ;-p, try not to use $_REQUEST['value'], when accessing the $_POST or $_GET vars, go directly to them, because when you use $_REQUEST you are making available more than just $_POST not to mention the overheads ie:-

$orderdate = (isset($_POST['orderdate']) ? $_POST['orderdate'] : '');

A simpler form :)

Cheers,
MRb
5:01 pm on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Agree fully with Matt here, but just to build on his comment about $_REQUEST I'll direct you to this thread [webmasterworld.com] where we discuss why not to use $_REQUEST in greater detail.
5:06 pm on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there Readie,

I can't type as fast as you as I am injured, so you beat me (again :)) to that thread I was going to edit my original post :)

Cheers,
MRb
5:22 pm on Apr 23, 2010 (gmt 0)

5+ Year Member



thx for the corrections =) and the useful information.

E Net Arch
 

Featured Threads

Hot Threads This Week

Hot Threads This Month