homepage Welcome to WebmasterWorld Guest from 54.227.40.166
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Retrieving a javascript value and creating a PHP variable?
I'd like to pass (this.form.orderdate.value) as a $_POST variable...?
mylungsarempty




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

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!

 

ENetArch




msg:4120846
 4:47 pm on Apr 23, 2010 (gmt 0)

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

ENetArch




msg:4120849
 4:48 pm on Apr 23, 2010 (gmt 0)

correction ...
location = "?orderdate='" + this.form.orderdate.value + "'";

Matthew1980




msg:4120857
 4:58 pm on Apr 23, 2010 (gmt 0)

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

Readie




msg:4120863
 5:01 pm on Apr 23, 2010 (gmt 0)

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.

Matthew1980




msg:4120871
 5:06 pm on Apr 23, 2010 (gmt 0)

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

ENetArch




msg:4120895
 5:22 pm on Apr 23, 2010 (gmt 0)

thx for the corrections =) and the useful information.

E Net Arch

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved