ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

SAEF and onsubmit.

July 23, 2007 3:50am

Subscribe [4]
  • #1 / Jul 23, 2007 3:50am

    Ty Martin

    232 posts

    Hi guys, I have the following example of an SAEF that, seemingly no matter what I try, just won’t enter data into the DB. I’m hoping another set of eyes will spot something I’m missing.

    {exp:weblog:entry_form weblog="items" return="test/tagtest/{segment_3}" preview="test/tagtest/{segment_3}"}
    
    Item: 
    <input type="text" autocomplete="off" name="title" id="title" onchange="copycat();"/>
    <span>/images/ajax-loader.gif</span>
    <div id="autocomplete_choices" class="autocomplete"></div>
    
    
    new Autocompleter.Local('title', 'autocomplete_choices', [{exp:query backspace="1" sql="SELECT cat_name FROM `exp_categories` WHERE group_id = 3"}'{cat_name}',{/exp:query}], {minChars: 1, indicator: 'indicator4'});
    
    function copycat() {
    $('category').value = $('title').value;
    }
    
    
    {custom_fields}
    
    {if relationship}
    <input type="hidden" id="{field_name}" name="{field_name}" value="{segment_3}">
    {/if}
    {/custom_fields}
    
    <input type="submit" name="preview" value="Preview" style="display: none" />
    
    <input type="hidden" name="status" value="Open" />
    
    <input type="hidden" name="entry_date" value="{entry_date}" />
    
    <input type="hidden" name="expiration_date" value="" />
    
    <input type="hidden" id="category" name="category" value="" />
    
    <input type="submit" name="submit" value="Submit" onclick="new Ajax.Updater('taglist', '/yum/', {onComplete:function(request, json){Element.hide('indicator3')}, onLoading:function(request, json){Element.show('indicator3')},parameters:Form.serialize(this.form),method:'post',asynchronous:true}); return false;" />
    
    {/exp:weblog:entry_form}

    There’s some AJAX (Prototype/Scriptaculous) in here but that doesn’t seem to be the issue. It’s returning the correct page, but when I go into the back end there’s no new entry.

    Also, and this is a second request that I can create a new topic for if necessary, but how can I create a new category from within the SAEF here? Is that possible?

    Thanks again!

    [Mod Edit: Moved to technical support from feature request.]

  • #2 / Jul 23, 2007 12:20pm

    Robin Sowell

    13255 posts

    The first thing I’d do- create a new template- put in a version of the above stripped of all of the ajax.  I suspect that’s the issue- or part of the issue- but I can’t replicate given I don’t have the extra scripts set up.

    Get the non-ajax version up- see if it does submit.  If so, we’ll know where the problem is.

  • #3 / Jul 23, 2007 12:38pm

    Ty Martin

    232 posts

    Just trying to get a non Ajax version working here now… but I could’ve sworn I posted this to the technical support forum.

    Updates soon. Thanks Rob1n

  • #4 / Jul 23, 2007 12:46pm

    Robin Sowell

    13255 posts

    LOL- not sure who moved it, but it was definitely moved over.  Almost slipped by me as it was fairly far down the list by the time I spotted it!

  • #5 / Jul 23, 2007 4:25pm

    Ty Martin

    232 posts

    Okay, so it’s working without the <strike>onsubmit</strike> onclick code in there. Is there a security reason why the SAEF won’t allow onsubmits? Is it really necessary to purchase Solspace’s OnSubmit extension?

  • #6 / Jul 23, 2007 4:46pm

    Lisa Wess

    20502 posts

    Hrm, I moved this originally but right now I’m going to have to pop it over to how-to since the standard form does, indeed work.  I’ll see if I can find an answer about this as well.

  • #7 / Jul 23, 2007 4:48pm

    Ty Martin

    232 posts

    Sounds good, I’m going to test this a bit further here too. Thanks Lisa.

  • #8 / Jul 23, 2007 6:04pm

    Derek Jones

    7561 posts

    It’s just outputting a standard HTML form, so if something isn’t working with your Javascript, you should use a Javascript console debugging tool to see where things are going wrong.  Since your form is working except for your Javascript event handling, start breaking things down: what happens when you submit an entry?  Have you stepped through your javascript code to make sure everything has the values you expect it to before the form data is submitted?  Is it submitting all form fields, including hidden ones?

  • #9 / Jul 23, 2007 6:14pm

    Ty Martin

    232 posts

    Hey Derek,

    Actually yes, that’s what I did. Here’s the POST:

    ACT=18&RET=http://www.mysite.org/yum/test/test/p2/&PRV=test/test/p2&URI;=/test
    
    /test/p2/&XID=85da80fb988bfa9592076e20895e5d3a&return_url=test/test/p2&author_id=1&weblog;_id
    
    =3&field_ft_11=none&field_ft_12=xhtml&site_id=1&title=Ski%20Jacket&field_id_12=p2&preview=Preview&status;=Open&entry_date=2007-07-23%2012:53%20PM&expiration;_date=&category=s&submit=Submit&submit=Submit

    What’s the difference between the return_url and the RET?

    Even when it submits the form successfully it’s not populating the field_id_12 it would seem (a related entry). Still debugging that too.

  • #10 / Jul 23, 2007 6:22pm

    Derek Jones

    7561 posts

    The forum’s XSS prevention is altering your code, wondermonkey, please zip and attach as a file.

    So, sometimes it does create the entry?

  • #11 / Jul 23, 2007 7:18pm

    Ty Martin

    232 posts

    That’s just the POST data from Firebug, which looks right to me.

    (What’s XSS?)

  • #12 / Jul 23, 2007 7:22pm

    Derek Jones

    7561 posts

    XSS.

    For example, see how the ‘://’ in your data became converted to :// to assist in the sanitization.  For anyone to help you, they will need to be able to see the full, unmodified post data being sent.  So, to follow up:

    1) please zip and attach as a file.

    2) sometimes it does create the entry?

  • #13 / Jul 23, 2007 7:29pm

    Ty Martin

    232 posts

    Thanks for the link. Interesting stuff.

    Ah, now I see the differences.  Attached.

    It works when I use a regular submit button but not when using an onclick for Ajax.Updater or Ajax.Request.

  • #14 / Jul 23, 2007 7:42pm

    Derek Jones

    7561 posts

    A quick glance shows the POST data to be okay.  I’d step through the javascript to make sure some basic things are happening, like posting to the correct URL.  If this is a development site, then you can also do some debugging in ExpressionEngine to do a quick check to make sure it’s receiving the form data, by adding the following to your index.php file:

    if (! empty($_POST))
    {
       foreach ($_POST as $key => $val)
       {
       echo $key.': '.htmlentities($val).'
    ';
       }
     
       exit;
    }

    This will dump the form data to the browser and exit the script without doing any processing.

  • #15 / Jul 23, 2007 7:46pm

    Ty Martin

    232 posts

    More tests:

    OnSubmit instead of OnClick works, but it submits the whole page instead of by XHR.

    Tried turning asynchronous to false and using onclick but nothing.

    Just got your test. You mean for me to pop that into the template in the return_url or into index.php? I’m going to try index.php (‘yum’ in my case).

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases