views:

226

answers:

6

The aim is to show a form which will update the div on the page with the result

  1. load this [page]
  2. click the linkto show the form
  3. submit the form

When submitting, the result does not show in the div if the form had been hidden.

  • after adding the code suggested in the below answers, I show the form, it gets submitted, but the data is not appearing in the div I give the ajaxForm as target

    [Here] is the same form that does show the result in the div

Thanks

A: 

In the example that doesn't work, if you bind the ajaxForm when you display the form it should work fine.

// you may want to use better/faster selector then 'a' but in this example it 
// will work
$('a').click(function () {
    $('#feditform').fadeIn('slow').ajaxForm(options);
    return false;
});

Add above instead of jQuery.facybox({ div: '#formDiv' }); return false and it should work as expected.

RaYell
That sounds great. However it seems not to work when I implemented it at http://plungjan.name/eetest/facy1.html - also will it be a problem that it does ajaxForm on every click? Thanks!
mplungjan
A: 

As far as I can see you now have:

<div id="formDiv" style="display:none"> some other code here </div>

but you still call $('#feditform').fadeIn('slow').ajaxForm(options);

as far as I can see and know about jQuery this will never show up, because the surrounding div is display:none. I suggest to do three things:

  • Do simplify the code first by using hide() and show(), which will avoid trouble with some animations. If this works, you can go on and introduce the animated versions again.
  • Just hide the content on the (document).ready function via jQuery, so you can rely on those functions. We had bad experiences with 'mixed' approaches (hardcoded and via jQuery) especially concerning show and hide situations.
  • Last but not least: Some plugins and environments do make troube using $. We tend to use the keyword jQuery in those situations because this will always keep the scope.

Hope this helps.

mic
Thanks, I was fading in the form, not the form div. The form is shown and some ajaxing is taking place, but the target div is not updated with the result. See my amended question. Thanks
mplungjan
Looking up the documentation it might help to put the `var options` part directly after and within the `(document).ready` as first part. May be the DOM chain within jQuery is broken if you don't do it this way. Haven't tested it. Just a guess.
mic
No - I did not expect it either since the alerts showed. But I guess the target div could have been out of scope - http://www.plungjan.name/eetest/facy3.html implements your suggestion
mplungjan
A: 

I don't think your problem is jQuery/Javascript related.

Once the form is submitted (through PHP I presume?) you need to echo a message which will be passed as part of the success callback. i.e.

echo '<strong>' . $_POST['message'] . '</strong>';

Care to post your server side code?

Marko
Sorry, I removed the first example that did work. It is here: http://plungjan.name/eetest/facy.html
mplungjan
I am now just returning THANK YOU and that also does not show
mplungjan
A: 

The data did appear for me in the link you posted.

If you think it is related to plugin conflict try jquery.noConflict() http://api.jquery.com/jQuery.noConflict/

While not the most elegant solution. It easily fixes any conflicts you have with plugins.

Nick011
If you click the link and submit the form from http://plungjan.name/eetest/facy2.html you get a dump of the form inside the div on the page???
mplungjan
+1  A: 

I'm not sure, but may be you init form with the wrong id?

$('#formDiv').fadeIn('slow').ajaxForm(options)

When form id is feditform. And in the correct example located on http://plungjan.name/eetest/facy.html $('#feditform').ajaxForm(options);

dmitko
DOH. Thanks Now SOMETHING happens. But it does not actually show anything. The target div is blank on return from the action.I have changed the form action to just load the text "thank you" but it is not showing
mplungjan
+1  A: 

When you submit the form, the request is sent to the server and you obtain a HTTP Error: 405 Method Not Allowed.

It looks like it comes from the configuration of your server. http://www.checkupdown.com/status/E405.html

Edit: as your code works for your example in the facy.html page I think it doesn't really comes from the server. The difference between the two examples are the action of the form.

  • fancy.html: you load a PHP file
  • fancy3.html: you load an HTML file

Did you try to call your thank you page "thanks.php" and modify the action of your form accordingly. I suppose that your server might not allow POST request on an HTML page.

Ben
Note: I used the Firebug extension to see this error. I recommend that you try with Firefox and with this extension: http://getfirebug.com/
Ben
I second that, looks like Ben has nailed the problem.
David Parunakian
Thanks. That did it. For some reason my "DUMP.php" does not work here.
mplungjan