Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • olst 69 posts 88 karma points
    Nov 05, 2011 @ 21:01
    olst
    0

    problematic chars for parameters of umbraco base

    Hi.

    I've set up a sign up form.

    now, I want to post the values using ajax, so I'm using base, and passing the form fields as parameters.

    The problem is that base does not accept special chars like '#' or '.' or '+', and this breaks the operation.

    does anybody have a workaround ?

     

    my jquery ajax code:

    $('#btnSignup').click(function () {
    
                    var firstName = $("#SignupFirstName").val();
                    var lastName = $("#SignupLastName").val();
                    var email = $("#SignupEmail").val();
                    var password = $("#SignupPassword").val();
    
    
                    $.ajax({
    

    url: '/Base/Ajax/GetSignup/' + firstName + '/' + lastName + '/' + email + '/' + password,

    beforeSend: function () { $('#signup-error').hide(); $('#loading').show(); }, success: function (data, textStatus, XMLHttpRequest) { $('#loading').hide(); var result = jQuery.parseJSON(data); $('#signup-error').fadeOut("slow").hide().fadeIn(); $('#message-text').text(result.Message); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); return false; });
  • Stephan Lonntorp 195 posts 212 karma points
    Nov 05, 2011 @ 21:12
    Stephan Lonntorp
    0

    Have you tried encoding your parameters before you send them? encodeURIComponent could be useful here.

     

     

  • olst 69 posts 88 karma points
    Nov 05, 2011 @ 22:10
    olst
    0

    Hi stephan, and thanks for the reply.

    I tried what you suggested, but still no go.

    Here is the jquery code:

    var firstName = $("#SignupFirstName").val();

                    var lastName = $("#SignupLastName").val();

                    var email = $("#SignupEmail").val();

                    var password = $("#SignupPassword").val();

     

                    var url = '/Base/Ajax/GetSignup/' + encodeURIComponent(firstName) + '/'

                        + encodeURIComponent(lastName) + '/' + 

                        encodeURIComponent(email) + '/' +

                        encodeURIComponent(password);

     

    and in the c# code I use this to get the original string:

    System.Net.WebUtility.HtmlDecode(firstName) ...

     

    Now, when I try to run the base method directly in the browser by typing the new url into the address, it gives an error, because I think there is some url decoding made behind the scenes in umbraco (???)

    What can I do to solve this ?

    The resource cannot be found

    Requested URL: /Base/Ajax/GetSignup/abc /abc/def/abc

  • olst 69 posts 88 karma points
    Nov 06, 2011 @ 14:05
    olst
    0

    So, does anybody have a solution ?

  • olst 69 posts 88 karma points
    Nov 06, 2011 @ 17:07
    olst
    0

    How is it possible to send the base function parameters without using the url for that, something like:

    var firstName = $("#SignupFirstName").val(),
        lastName
    = $("#SignupLastName").val(),
        email
    = $("#SignupEmail").val(),
        password
    = $("#SignupPassword").val();

    $
    .ajax({
        url
    :'/Ajax/GetSignup/',
        type
    :'POST',
        data
    :{
            firstName
    : firstName,
            lastName
    : lastName,
            email
    : email,
            password
    : password
       
    },
        success
    :function(result){
           
    // TODO: process the results from the AJAX call
       
    }
    });

  • ashwinth 1 post 21 karma points
    Nov 10, 2011 @ 16:42
    ashwinth
    0

    Not sure if this helps, but i had a similar problem passing an email to base. I kept getting a 404 error when the email parameter was the last in the list of parameters; so my last parameter couldnt contain special characters (most probably the . in the email).

    /base/Services/AddSubscriber/[email protected] - didnt work
    /base/Services/AddSubscriber/[email protected]/newsletter worked

    Thansk,
    Ashwinth

  • Kjetil Barnung 3 posts 28 karma points
    Nov 11, 2011 @ 17:12
    Kjetil Barnung
    0

    on IIS 7.5 i find /base to break when any of the parameters you pass contains a dot

  • olst 69 posts 88 karma points
    Nov 11, 2011 @ 19:58
    olst
    0

    Yes, you are both right, you cannot pass an full email address to base as a parameter, so what I did was was not pass the parameters to the base function, but rather in my base function use the request object instead and convert it to json, like so:

     

    string post = HttpContext.Current.Request.Form[0];
    SignupInput si = (SignupInput)JsonConvert.DeserializeObject(post, typeof(MyType));
  • Henri Toivonen 77 posts 111 karma points
    Dec 12, 2011 @ 15:11
    Henri Toivonen
    0

    Ugh, this is such a small issue but still i manage to bash my head bloody every time i run into this problem.

    It would be great if /base got some bugfixes really soon.

    Does anyone have any good ideas? Just manually replace in both ends to some kind of special char?

    Getting the request.form is not a good solution in my case since this is in a GET.

Please Sign in or register to post replies

Write your reply to:

Draft