Jump to content

Get value from input


sanl

Recommended Posts

I have a variable $getdate in my php file. And I have input in TPL file: <input type="date" name="getdate">

 

Customer can choose a date and how to get this input value from TPL file to my php variable? $getdate variable in php file help me to make a sql request. 

 

 

Link to comment
Share on other sites

 

if your form with this input is posted you can use Tools class:

Tools::getValue('getdate');

I still got 0 results.

 

In back office page I would like to see list of customers WHERE date_add > $getdate.

 

PHP CODE:

$date22= Tools::getValue('getdate');
 

sql =  'SELECT firstname, lastname FROM ps_customers WHERE date add >= $date22;

 

TPL FILE code:

<input id="getdate" type="date" name="getdate">

Link to comment
Share on other sites

your form must be posted and you have to use Tools function in executed hook function, or in __construct function of your module

Okey, im trying to get result without form. 

 

Im using default mymodule module (prestashop16 for developers how to create module) where I can change MYMODULE_NAME so I have just change this input type: from text to date. 

 

I would like to use this input to get date and use this date in my sql query. 

 

$sql = 'SELECT cu.firstname , cu.lastname , cu.email
   FROM ps_customer cu
WHERE  cu.date_add >= $my_module_name'
 
If i use cu.date_add >= ('2014-07-24') it works. IF i use $my_module_name (as i said I change this variable input to date type so it should be date). I got error: PrestaShopDatabaseException - Unknown column '$my_module_name' in 'where clause'. 
 
 
After settings block I include tpl file which table where is my data from DB. Everything works fine, but I can`t figure out how to get input date value and use it in my sql query. 
Link to comment
Share on other sites

you use apostrophe $sql= 'here'

 

it means that everything between apostrophes will be treated as a string not as variable

to use variable you have to use " " instead of ' ' 

or just don't use " and '

It works , thank u:)

 

I used sql = "      MY QUERY >= ('$VARIABLE')            "

Also I tryed Tools:getValue

$myVar = strval(Tools::getValue('date'));
Thank u!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...