0

I have the server programmed in Cherrypy and I use also Mako Template.

And I have the variable dict (variable Mako that contain information's work) for working with the user( this I have to use Mako and JAvascript).

I have one problem that I can not pass the value's Mako to Javascript.

MAKO --->>> JAVASCRIPT and vicecersa Not can to pass.

When the user wants change the information, I need to use the form. The information is for example the data is the identifying a person.

When I connect when the server localhost:8100 and I have in automatically dict on Url.

The user pushes the button's send.(submit) in case of change. The server receipt the value in Javascript with the separator in Js and the old in MAko. I have the problem for read and to convert the separator in Javascript.

It possible to change the string's submit's form While or before to sending?

I want to program the submit's form because I want to use the other delimiter(not & and =).

This is possible?

Now I write one example:

www.theuser.com/?Name=IBM&surname=PC

With if the function programmable while sending

www.thepc.com/?Name%24+IBM+%23%+Surname%24+PC

Repeat: when I sent the parameter, I not want this separator & or = and I want to use the others. Separator

    javascript              Mako           

      =                       %24+
      &                       +%23+

This Query String is the original for the my project:

http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+script.sh+parameters+%23+proc1_chk_make%24+on+%23+outputp2_value%24++%23+demo_input_description%24+hola+mundo+%23+outputp4_visible%24+on+%23+outputp4_info%24++%23+inputdata1_max_pixels%24+1024000+%23+tag%24++%23+outputp1_id%24+nanana+%23+proc1_src_compresion%24+zip+%23+proc1_chk_cmake%24+off+%23+outputp3_description%24++%23+outputp3_value%24++%23+inputdata1_description%24+input+data+description+%23+inputp2_description%24+bien%3F+%23+inputp3_description%24+funciona+%23+proc1_cmake%24+-D+CMAKE_BUILD_TYPE%3Astring%3DRelease++%23+outputp2_visible%24+on+%23+outputp3_visible%24+on+%23+outputp1_type%24+header+%23+inputp1_type%24+text+%23+demo_params_description%24+va+bien+%23+outputp1_description%24++%23+inputdata1_type%24+image2d+%23+proc1_chk_script%24+off+%23+demo_result_description%24+win%3F+%23+outputp2_id%24+nanfdsvfa+%23+inputp1_description%24+funciona+%23+demo_wait_description%24+boh+%23+outputp4_description%24++%23+inputp2_type%24+integer+%23+inputp2_id%24+papapa+%23+outputp1_value%24++%23+outputp3_id%24+nananartrtrt+%23+inputp3_id%24+pepepe+%23+outputp3_type%24+header+%23+inputp3_visible%24++off+%23+outputp1_visible%24+on+%23+inputdata1_id%24+id_lsd+%23+outputp4_value%24++%23+inputp2_visible%24+on+%23+proc1_source%24+lsd-1.5.zip+%23+inputp3_value%24+si+%23+proc1_make%24+-j4+-C++%23+images_config_file%24+cfgmydemo.cfg+%23+outputp2_type%24+header+%23+proc1_subdir%24+xxx-1.5+%23+proc1_url%24+http%3A%2F%2Fwww.ipol.im%2Fpub%2Falgo%2F...+%23+inputdata1_image_depth%24+1x8i+%23+inputp1_id%24+popopo+%23+inputp1_value%24+si+%23+inputp2_value%24+no+%23+demo_data_filename%24+data_saved.cfg+%23+inputdata1_info%24+info_lsd+%23+outputp3_info%24++%23+inputdata1_image_format%24+.pgm+%23+outputp1_info%24++%23+inputdata1_compress%24+False+%23+inputp1_visible%24+on+%23+proc1_id%24+lsd+%23+outputp4_id%24+nana+%23+outputp2_description%24++%23+outputp4_type%24+header+%23+outputp2_info%24++%23+inputp3_type%24+float+%23+&tag=&inputp4_id=hi&inputp4_type=text&inputp4_description=hello+program&inputp4_value=no&inputp4_info=bol&inputp4_visible=on

For the moderator: I read on the post https://stackoverflow.com/questions/13353539/how-to-change-how-the-url-is-encoded-when-a-form-is-submitted But this was not interested in me.

P.s. The solution in Jquery or Javascript is equal for me.

Community
  • 1
  • 1
Mirko Cianfarani
  • 2,023
  • 1
  • 23
  • 39
  • Your question is not very clear. Can you put things in very simple terms? – RobG Mar 27 '13 at 00:39
  • 5
    You *can* change this, but you would have to implement everything manually (build a URL from each form field's name and value then change the document's href). But you *shouldn't* do this. Just adapt the receiving script to cope with the standard delimiters. There's a reason they're standard. – Dave Mar 27 '13 at 00:43
  • 1
    @RobG I believe (but could be wrong) that he wants to change a form so that instead of submitting by GET to `myparser.php?field1=value1&field2=value2` it goes to `myparser.php?field1%24value1+%23%+field2%24value2`. I can only imagine he's worried about users typing `=` or `&` and is unfamiliar with percent encoding. – Dave Mar 27 '13 at 00:45
  • @dave your understand my idea or mind. But how to change this submitting by GET to myparser.php?field1=value1&field2=value2 it goes to myparser.php?field1%24value1+%23%+field2%24value2. – Mirko Cianfarani Mar 27 '13 at 00:55
  • I don't worried about users typing = or & – Mirko Cianfarani Mar 27 '13 at 00:56
  • Look on this article http://www.sislands.com/coin70/week6/encoder.htm Ad you try for decode this new url with the separator %24 and other – Mirko Cianfarani Mar 27 '13 at 00:56
  • 1
    How does your user interface look like at all, how does it use JS? And why can't you make your server just accept the standard delimeters (instead of these fancy `$`/`#` things)? – Bergi Mar 27 '13 at 01:05
  • Because the server is python and this used the separator in python is $ and # http://www.degraeve.com/reference/urlencoding.php – Mirko Cianfarani Mar 27 '13 at 01:09
  • Dict is derivative to a File Json – Mirko Cianfarani Mar 27 '13 at 01:10
  • @Bergi With Javascript I send the delimiters & and = and I need to change for using the separator in python $ and #. And when the server read the url , it in autocamilly decoding!!! – Mirko Cianfarani Mar 27 '13 at 01:12
  • So you need to serialise the form (there are many examples on the web how to do that) then use a regular expression to replace the & and = characters with their encoded values before sending it to the server. – RobG Mar 27 '13 at 05:48

1 Answers1

1

Well I'm pretty sure your reasons for doing this don't justify doing it, but to answer the question, this is how you would change the tokens. I'm assuming jQuery, it's not entirely necessary but makes the code shorter.

HTML:

<form id="myform" action="myparser.php">
<input ...>
</form>

JavaScript:

$('#myform').submit(function(e){
    e.preventDefault();
    var q=$(this).attr('action'),f=this.elements,i;
    for(i=0;i<f.length;++i){
        q+=(i===0?'?':'+%23%+')+f[i].name+'%24'+f[i].value;
    }
    document.location.href=q;
    return false;
});

That's slightly minified, so here's the gist. We begin by binding to the submit event, which we prevent (preventDefault and return false to be doubly sure), then get all the form's elements (this.elements) and iterate through them. By the end of the loop, q is a full URL which we want to submit to (using the action property and filling in all the names/values), so we just set the HREF to it and off we go. In this case to myparser.php.

Note that this does no character substitution whatsoever. You should make f[i].value safe in some way. From your question, it seems obvious that you don't want standard URL encoding, but you will need to do something to prevent bad characters being used.

Finally, this is just the sending side. You'll still need to do something clever on your server-side to actually read these values.

Dave
  • 44,275
  • 12
  • 65
  • 105
  • Excuse me I don't have the file in php and you do not worry. Now I know for changing for my project – Mirko Cianfarani Mar 27 '13 at 01:14
  • 1
    Sure, it doesn't matter what script you send to. I just use PHP as a generic "server script" marker when I'm talking about websites. – Dave Mar 27 '13 at 01:15
  • Excuse me @david... where can I find some sites that explain these things? Or Pass me the sites that help in my case? – Mirko Cianfarani Mar 27 '13 at 01:17
  • Depends what you want to know. jQuery is well documented here: http://api.jquery.com/. For generic JavaScript, Google is your friend (I found `.elements` from a quick search). For python-as-a-server, no idea, maybe this will help you: http://stackoverflow.com/a/8929395/1180785 – Dave Mar 27 '13 at 01:25
  • There's a bit more to serialising a form that just iterating over the controls and getting their values. You must deal with checkboxes, radio boxes, multiple selects, disabled controls, those with no name, etc. But I think your the general strategy is sound. – RobG Mar 27 '13 at 02:13
  • @RobG Good point. I hadn't considered checkboxes and radio buttons. Inputs with no name shouldn't matter, since he has control over the form, and I would have thought this method would work with disabled controls (?). – Dave Mar 27 '13 at 02:16
  • I have the form in the Window's dialog and seems that is not running inside the function(e){ New Problem XD – Mirko Cianfarani Mar 27 '13 at 02:26
  • @MirkoCianfarani maybe you forgot to set the ID on the form? If you can't fix it, you should post it as a new question with more context. – Dave Mar 27 '13 at 02:45
  • Always the moderator not will close for duplicate question. – Mirko Cianfarani Mar 27 '13 at 12:23