0

I've seen questions similar to this one, but still didn't find the solution, and this is really wasting my time :(

Here's my controller

public function test() {
 print_r($_POST);
 return;
}

View

<?php 
 echo form_open(base_url('go/test'), 'id="update" autocomplete="off" ajax-hidden'); 
 echo form_hidden('id', $id); 
?>
 <input id="update" name="number" class="spinner" readonly="readonly" 
 value="<?$=value?>"/>
<?php 
 echo form_close();
?>

I'm using jQuery to submit the form once the jQuery UI spinner is changed. This is the response:

Array()
Marc Audet
47k11 gold badges68 silver badges86 bronze badges
asked Jun 11, 2013 at 18:33
3
  • I must add that other forms in the website work fine Commented Jun 11, 2013 at 18:35
  • That input doesn't seem to have a type, should it be type="hidden" ? Probably not the cause. Commented Jun 11, 2013 at 18:39
  • stackoverflow.com/questions/14201815/… see and check Commented Jun 11, 2013 at 18:41

4 Answers 4

3

Most likely jQuery is not able to get a value to pass over to your Controller because your form and input elements have the same id update

Also <?$=value?> is incorrect syntax. It should be <?= $value ?>

answered Jun 11, 2013 at 18:38
Sign up to request clarification or add additional context in comments.

Comments

2

Also you should use codeingiters post handlers $something = $this->input->post('something');

http://ellislab.com/codeigniter/user-guide/libraries/input.html

answered Jun 11, 2013 at 18:41

Comments

1

Change your input id to something other than "update" And change < ?$=value > to < ?=$value >

<input id="myInput" name="number" class="spinner" readonly="readonly" value="<?= $value?>"/>
answered Jun 11, 2013 at 18:40

Comments

1

I forgot that I changed my ajax handler to work with IE and didn't change the ajax function for this particular form, because this form's response should be hidden, so it uses a different ajax handler.

This is my main submit function:

(function($){
 jQuery.fn.ajaxFormSubmit =
 function(container, data) {
 var url = $(this).attr('action');
 $.ajax({
 url: url,
 type: "POST",
 data: data,
 dataType: "html",
 success: function(msg) {
 $(container).html(msg);
 }
 });
 return this;
 };
})(jQuery);

I used to serialize the form data inside this function but then I realized it didn't work for IE, the only solution was to serialize the form data before doing anything else!

Here are the 2 functions I'm using:

$('form[ajax]').live('submit', function(e){
 e.preventDefault();
 var data = $(this).serialize();
 var container = $(this).attr('cont');
 if (typeof container == 'undefined' || container == false) {
 container = '.#ajax';
 }
 $(container).html('<img src="public/images/ajax.gif"/>');
 $(container).fadeIn('fast');
 $(this).ajaxFormSubmit(container, data);
});
$('form[ajax-hidden]').live('submit', function(e){
 e.preventDefault();
 var data = $(this).serialize();
 var container = '';
 $(this).ajaxFormSubmit(container, data);
});

The second function simply didn't have the data variable. So I added it. Hope this can help someone.

answered Jun 11, 2013 at 22:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.