Insert into DB from a javascript or FORM within PHPrad May 25, 2020, 09:34:18 PM Good Day communityI am working with PHPrad Classic since 5days and some of the magic of the framework has not yet opened to me.Currently I am trying to include jquery Seats into my test page and update the DB from seat choices made with javascript.I read in this forum, that this may be possible to do with a html-form fired by javascript.But how may I insert the information coming from $_POST or $_GET form values into the db ?I tried to write a static php script but cannot instanciate the db connection : unknown Controller when I try to create a new instance of my controller for the db pointer or try to work with $this.My next try was to add a custom "add" page but could not find how to fill out page fields by POST or GET form informations.Who can give me the right hint where my mistake is ?Kind regards Quote Selected
Re: Insert into DB from a javascript or FORM within PHPrad Reply #1 – May 26, 2020, 08:49:45 PM @jsa what are you trying to archive, then I can point you in the right direction. Quote Selected
Re: Insert into DB from a javascript or FORM within PHPrad Reply #2 – May 27, 2020, 07:45:30 AM Hi @willvin I will try to explain it.I try to include Jquery-Seat-Chart (https://github.com/mateuszmarkowski/jQuery-Seat-Charts) into my first page with PHPRad.It shows up and works with some restrictions caused by the separation between server side php and the jquery client side plugin.Two problems are now unresolved:I write and fill up a html form with jquery-seats and will fire this form up against a PHP server side page doing the db connection and save the givven informations.First try was a page under app/views/partial but a can't establish a connection with the db because I don't know how to instanciate it. With ... $cmtc = new PresenceController; $db = $cmtc->GetModel(); my Controller is unknown.And the second problem is how can I use a Page OnLoad with PHPRad to change for example my seat chart with javascript and informations coming from the db. I am currently trying to solve this with a "After View List" command with "window.onload" with the same problems caused by to less knowledge (sc unknown).Quote$seatList = $db->rawQuery("select `m`.`firstname` AS `firstname`,`m`.`lastname` AS `lastname`,`p`.`comment` AS `comment`,`p`.`channel` AS `channel`,date_format(`p`.`date_created`,'%d.%m.%y %H:%i') AS `datef`,date_format(`e`.`event_date`,'%d.%m.%Y') AS `edate`,to_days(`e`.`event_date`) - to_days(current_timestamp()) AS `days`,`m`.`seat` AS `seat` from ((`presence` `p` join `members` `m`) join `events` `e`) where `p`.`presence` = 'excused' and `m`.`id` = `p`.`member_id` and `e`.`id` = `p`.`event_id` order by `m`.`loginname`");//update the seat mapecho " <script>"; echo " window.onload = function seatUpdate() { "; foreach ($seatList as $seat) { echo "sc.status('" . $seat['seat'] . "','unvailable') //set status for one seats \n\n"; }echo " }";echo " </script>"; Thanx for your try to help me. Quote Selected
Re: Insert into DB from a javascript or FORM within PHPrad Reply #3 – May 27, 2020, 10:52:02 AM @you can create an API to handle your query in the ApiController.php and you can add you onload js code to Custom JS or in ClientEvents in an input field. you can read more about code structure here. And please make sure the controller you are instantiating exist.Note: creating an API with a link as this http://localhost/{your-project-name}/api/test is as simple as creating a function like thisCode: [Select]function test(){// write your code to do whatever you want and return your result.} in ApiController.php. Quote Selected