Welcome Guest, Not a member yet? Register   Sign In
facing problems with inserting data
#11

(This post was last modified: 02-12-2018, 02:32 PM by dave friend.)

You mean the "Send Now" button - right?

I don't see the "savesms()" method anywhere. While looking for it I notice that you have a controller and model that are both named "sms". You probably shouldn't do that. Perhaps name the model "sms_model".

The next problem of note is with using sms_form() with the $.post(... call. $.post(... expects data to be returned by the server but you make a redirect() instead. That's wrong. Echo some data in reply instead. Here's one way but it is presented without knowledge of what happens in "savesms()" so it's maybe not the best solution.

PHP Code:
public function sms_form()
    {
        
$save = array(
            
'sender'           => $this->input->post('sender'),
            
'recepients'       => $this->input->post('recepients'),
            
'body'             => $this->input->post('body'),
            
'sendscheduletime' => $this->input->post('sendscheduletime'),
        );
        
//if savesms() returns false when saving fails then use
        
echo $this->sms->savesms($save) ? "Success" "Fail";
    } 

Looking more closely at your <form> I cannot find an <input> for either 'sender' or 'sendscheduletime'. So your $save array will have NULL values for those two items.

Just to make sure the "Send Now" button 'click' event is being handled do this test.

Code:
$("#SendSMS").click(function () {
    event.preventDefault();
    alert('Send SMS Clicked');
   // var postData = $('#SendSMSForm').serializeArray();

   // $.post("<?php echo base_url('sms/sms_form') ?>", postData)
           // .done(function (data) {
             //   alert("Data Loaded: " + data);
          //  });
});
Reply
#12

Yes that's the button. Thank you dave, the Sender should be static like only from one person,how do i achieve this? as for the sendscheduletime it should store the date and time as they are picked, i will change that and tell you how it works
Reply
#13

I have no clue as to what the value that represents the "sender" should be. Whatever it is it should be passed from the controller that loads the form view.
Reply
#14

It still does not send, even the console does not show any action
Reply
#15

(This post was last modified: 02-12-2018, 11:37 AM by CharlesK.)

I actually found where the problem was, in this code:
$("#SendSMS").click(function () {
event.preventDefault();
alert('Send SMS Clicked');
// var postData = $('#SendSMSForm').serializeArray();

// $.post("<?php echo base_url('sms/sms_form') ?>", postData)
// .done(function (data) {
// alert("Data Loaded: " + data);
// });
});


after the function we should have the event defined inside the brackets,such that it looks like this:
$("#SendSMS").click(function (event) {
event.preventDefault();
alert('Send SMS Clicked');
// var postData = $('#SendSMSForm').serializeArray();

// $.post("<?php echo base_url('sms/sms_form') ?>", postData)
// .done(function (data) {
// alert("Data Loaded: " + data);
// });
});

this returns the alert message
Reply
#16

(This post was last modified: 02-12-2018, 11:44 AM by dave friend.)

OK, so you removed the "alert('Send SMS Clicked');" line and un-commented the other lines and now the console shows the action?

The click handler should look like this.

Code:
$("#SendSMS").click(function (event) {
    event.preventDefault();
    var postData = $('#SendSMSForm').serializeArray();

    $.post("<?php echo base_url('sms/sms_form') ?>", postData)
            .done(function (data) {
                alert("Data Loaded: " + data);
            });
});

Note the first line where 'event' was added to the function
Reply
#17

(This post was last modified: 02-12-2018, 11:59 AM by CharlesK.)

Yes i already did that, am having a syntax error in the controller here:
Code:
echo $this->sms->savesms($save) ? "Success" : "Fail";
           [s]redirect('modal_send_sms');[/s]

There seems to be missing something:The error says "syntax error unexpected 'redirect' (T_STRING)"
Reply
#18

(This post was last modified: 02-12-2018, 02:35 PM by dave friend.)

Remove the redirect call. I have no idea how the redirect('modal_send_sms'); line wound up in my code. It's wrong.

Wait. I do know. I was trying to use 'strikethrough' text formatting on that line. Seems that doesn't work for a code block. Sorry. I've edited the previous post where that appeared. It was supposed to look like this redirect('modal_send_sms');
Reply
#19

Nothing happens when i remove the line of code
Reply
#20

What does dev tools show as the response to the ajax call?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB