Welcome Guest, Not a member yet? Register   Sign In
How to implement EventSource on Codeignigter app?
#21

(This post was last modified: 02-25-2020, 10:08 AM by SmokeyCharizard.)

(02-24-2020, 10:05 PM)dave friend Wrote: Send me a PM telling me where your repo is and I'll take a peek.
So I sent you the repo, but I can't tell if you got it. I did find that I am also sending cURL requests along with the SOAP requests. I think this is what might be conflicting with everything, as I can send SSE's from the model until I make my first cURL request.

EDIT: scratch that, the data values were just not being passed via fetch. This is going to work! Thanks!
Reply
#22

You sent it how?
I have not received anything except the link to a GitHub page which did not work.

But it sounds like you're making progress. Good.
Reply
#23

(02-25-2020, 10:23 AM)dave friend Wrote: You sent it how?
I have not received anything except the link to a GitHub page which did not work.

But it sounds like you're making progress. Good.
I sent it as a private message, but I suppose it doesn't matter any more! Now I just need to figure out how to send the form data to the controller via fetch. I am calling the controller, but the data isn't getting passed...

You've been a MAJOR help, though!
Reply
#24

(02-25-2020, 10:38 AM)SmokeyCharizard Wrote: I sent it as a private message, but I suppose it doesn't matter any more! Now I just need to figure out how to send the form data to the controller via fetch.

Try something like this to post the form data.

Code:
const form = new FormData(document.getElementById('login-form'));
fetch('/login', {
  method: 'POST',
  body: form
});
Reply
#25

(This post was last modified: 02-25-2020, 01:06 PM by SmokeyCharizard.)

(02-25-2020, 11:51 AM)dave friend Wrote:
(02-25-2020, 10:38 AM)SmokeyCharizard Wrote: I sent it as a private message, but I suppose it doesn't matter any more! Now I just need to figure out how to send the form data to the controller via fetch.

Try something like this to post the form data.

Code:
const form = new FormData(document.getElementById('login-form'));
fetch('/login', {
  method: 'POST',
  body: form
});
I managed to display this...

"------WebKitFormBoundaryBkqBFPIomAOOTUPR
Content-Disposition:_form-data;_name"]=>
  string(187) ""date"

2019-10-03 09:44:30
------WebKitFormBoundaryBkqBFPIomAOOTUPR
Content-Disposition: form-data; name="dateTo"

2019-10-03 09:46:30
------WebKitFormBoundaryBkqBFPIomAOOTUPR--
"
  [0]=>
  string(187) ""date"

2019-10-03 09:44:30
------WebKitFormBoundaryBkqBFPIomAOOTUPR
Content-Disposition: form-data; name="dateTo"

2019-10-03 09:46:30
------WebKitFormBoundaryBkqBFPIomAOOTUPR--
"

How to I parse this to just the the date, dateTo, and sandbox? I tried json_encode() to no avail.

My fetch code:


  const url = <?= "'".base_url('classic/classicFirearmByDate', 'http')."'"; ?>;

  var myHeaders = new Headers();
  myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

  const form = new FormData(document.querySelector('#form1'));

  // The parameters we are gonna pass to the fetch function
  let fetchData = {
      method: 'POST',
      headers: myHeaders,
      body: form,
  }

Reply
#26

I'm not very confident I understand the question. If you're asking how you get the form inputs at the controller - that is not changed from your original post.

PHP Code:
$date trim(htmlspecialchars($this->input->post('date'))); 
Reply
#27

(This post was last modified: 02-25-2020, 03:27 PM by SmokeyCharizard.)

(02-25-2020, 02:54 PM)dave friend Wrote: I'm not very confident I understand the question. If you're asking how you get the form inputs at the controller - that is not changed from your original post.

PHP Code:
$date trim(htmlspecialchars($this->input->post('date'))); 
Thanks for the reply! I should have been more specific in my response,
Yes, it seems like fetch will only send the form data in a format like above, with the weird "WebKitFormBoundary" stuff. I tried your trim solution, but it returned an empty string.

EDIT: I figure it out. The header was causing problems lol!
Reply
#28

(This post was last modified: 02-25-2020, 03:38 PM by dave friend.)

(02-25-2020, 03:16 PM)SmokeyCharizard Wrote: Thanks for the reply! I should have been more specific in my response,
Yes, it seems like fetch will only send the form data in a format like above, with the weird "WebKitFormBoundary" stuff. I tried your trim solution, but it returned an empty string.

Let me try again.

At the controller function classicFirearmByDate() you can capture the form input fields by using

PHP Code:
$date $this->input->post('date');
$toDate $this->input->post('to-date'); 


Don't worry or mess with the "WebKitFormBoundary" stuff. The server will parse that and put the <input> data into $_POST just like when you use a normal <form> submit.

The trim and htmlspecialchars calls were code you had in your original post, so I left them in place.
Reply
#29

(This post was last modified: 02-25-2020, 04:04 PM by SmokeyCharizard.)

(02-25-2020, 03:30 PM)dave friend Wrote:
(02-25-2020, 03:16 PM)SmokeyCharizard Wrote: Thanks for the reply! I should have been more specific in my response,
Yes, it seems like fetch will only send the form data in a format like above, with the weird "WebKitFormBoundary" stuff. I tried your trim solution, but it returned an empty string.

Let me try again.

At the controller function classicFirearmByDate() you can capture the form input fields by using

PHP Code:
$date $this->input->post('date');
$toDate $this->input->post('to-date'); 


Don't worry or mess with the "WebKitFormBoundary" stuff.  The server will parse that and put the <input> data into $_POST just like when you use a normal <form> submit.

The trim and htmlspecialchars calls were code you had in your original post, so I left them in place.
I figured it out. If you remove the header setting I have, then it submits! Unfortunatly, I can seem to send any messages in my model if the echo is inside of the main process loop. I'll pm you my github so you can see.

(02-25-2020, 03:30 PM)dave friend Wrote:
(02-25-2020, 03:16 PM)SmokeyCharizard Wrote: Thanks for the reply! I should have been more specific in my response,
Yes, it seems like fetch will only send the form data in a format like above, with the weird "WebKitFormBoundary" stuff. I tried your trim solution, but it returned an empty string.

Let me try again.

At the controller function classicFirearmByDate() you can capture the form input fields by using

PHP Code:
$date $this->input->post('date');
$toDate $this->input->post('to-date'); 


Don't worry or mess with the "WebKitFormBoundary" stuff.  The server will parse that and put the <input> data into $_POST just like when you use a normal <form> submit.

The trim and htmlspecialchars calls were code you had in your original post, so I left them in place.
Encase you can't see my message again, here's the pastebin. https://pastebin.com/eupHEA0c
Reply
#30

(02-25-2020, 03:58 PM)SmokeyCharizard Wrote: Encase you can't see my message again, here's the pastebin. https://pastebin.com/eupHEA0c

I can see your PM.
I cannot send a reply to you.
Go the the edit options of your profile and check the box next to Receive private messages from other users.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB