// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'ship_to', 'ship_to_id')
->fields(
Field::inst( 'ship_to_customer_id' )->setvalue($customer_id),
Field::inst( 'ship_to_delivery_address_1' ),
Field::inst( 'ship_to_id' ),
Field::inst( 'ship_to_delivery_address_2' ),
Field::inst( 'ship_to_delivery_town' ),
Field::inst( 'ship_to_delivery_county' ),
Field::inst( 'ship_to_delivery_postcode' )
)
I have it in the URL of the page calling the shipto.php file using serverside on the rendered page, and I am also storing it in a cookie - both called 'customer_id'.
This W3Schools $_GET example shows how to pass variables in the URL and to use $_GET to get them. Start by using the browser's network inspector to make the URL is formatted as expected.. If you still need help please post your code or better a link to your page or a test case replicating the issue so we can offer suggestions. https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
I am familiar with how $_GET works. My problem is thet when I define it in the server side php file it does not read it in. Nor when I read the cookie ($_COOKIE). If I hard code an ID it works perfectly, but I need a dynamic variable for 'customer_id' to be passed in.
$customer_id = $_GET['customer_id'] // does not work
$customer_id = $_COOKIE['customer_id'] // does not work
$customer_id = 123 // does work
OK, I think I made progress... I am now editing the editor .js file and am now getting data in the url for datatables and for editor. The URL in inspector is respecting the change in URL and the $_GET is now working in the editor php file... can you offer any advice as to how I get a PHP variable into the url string in the ajax url?
Thanks for your help so far Kevin, I can not share the page as it is secure. Everything is working great, I just need to get a PHP variable into thos URL's in editor and datatables ajax areas.
I did, yes. Thanks Kevin. This is getting lost in translation. I just need to pass a single variable into the js file, in both datatabkes and editor. It is all working just as it should, barring the use of the correct variable. If I hard code it, it works, so how why do I need to reading up on GET and POST requests. I am sorry, but I am obviously not being clear enough. I don't know how else to phrase my problem - it seems pretty clear. I have already progressed just through trial and error...
Doing this probably won't work if the customer_id changes. It will probably be statically assigned to whatever the value is when initialized. Taht is why you need to use the ajax.data option as a function like the example.
Answers
```
<?php
$customer_id = 277;
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../datatables/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
<?php > ``` ?>Editor::inst( $db, 'ship_to', 'ship_to_id')
->fields(
Field::inst( 'ship_to_customer_id' )->setvalue($customer_id),
Field::inst( 'ship_to_delivery_address_1' ),
Field::inst( 'ship_to_id' ),
Field::inst( 'ship_to_delivery_address_2' ),
Field::inst( 'ship_to_delivery_town' ),
Field::inst( 'ship_to_delivery_county' ),
Field::inst( 'ship_to_delivery_postcode' )
)
How are you trying to get the customer_id parameter?
How are you passing the parameter?
Kevin
I have it in the URL of the page calling the shipto.php file using serverside on the rendered page, and I am also storing it in a cookie - both called 'customer_id'.
This W3Schools $_GET example shows how to pass variables in the URL and to use $_GET to get them. Start by using the browser's network inspector to make the URL is formatted as expected.. If you still need help please post your code or better a link to your page or a test case replicating the issue so we can offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I am familiar with how $_GET works. My problem is thet when I define it in the server side php file it does not read it in. Nor when I read the cookie ($_COOKIE). If I hard code an ID it works perfectly, but I need a dynamic variable for 'customer_id' to be passed in.
I see this in your script:
Sounds like you are using an HTTP POST instead of GET. See this example of sending parameters along with this example of POST requests.
gain if this doesn't help please post your client side code so we can see what you are doing. Or better a link to your page or test case.
Kevin
OK, I think I made progress... I am now editing the editor .js file and am now getting data in the url for datatables and for editor. The URL in inspector is respecting the change in URL and the $_GET is now working in the editor php file... can you offer any advice as to how I get a PHP variable into the url string in the ajax url?
The URL in inspector now shows these URL's, so now all I have to do is...
In the editor ajax section I want to replace the 277 with a php variable
In the datatables url section I want to replace the 277 with a php variable
Thanks for your help so far Kevin, I can not share the page as it is secure. Everything is working great, I just need to get a PHP variable into thos URL's in editor and datatables ajax areas.
Did you see the example of sending parameters link I posted above?
Kevin
I did, yes. Thanks Kevin. This is getting lost in translation. I just need to pass a single variable into the js file, in both datatabkes and editor. It is all working just as it should, barring the use of the correct variable. If I hard code it, it works, so how why do I need to reading up on GET and POST requests. I am sorry, but I am obviously not being clear enough. I don't know how else to phrase my problem - it seems pretty clear. I have already progressed just through trial and error...
Sorry I posted the wrong link. See this example of sending parameters.
Kevin
I have sorted it. On the page calling the js script for datatables / editor I declared the variable in javascript
Then I called that variable in both ajax locations like this
and like this
No changes to POST / GET, just getting the syntax / method correct for passing a simple variable...
Doing this probably won't work if the customer_id changes. It will probably be statically assigned to whatever the value is when initialized. Taht is why you need to use the
ajax.data
option as a function like the example.Kevin