Re: [Zope] redirection from within forms with submit button
Hello Andy
Must admit I cant be bothered to read all this but some notes:
<input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">>">
This is pointless, the page will never be rendered because it will instantly do the redirect. If you could refactor this a bit to more concise question...
Gosh, you're harsh. I'll try. Why the instant redirection? I want to make the redirection conditional on clicking the submit button. Why _does_ it work as I'd like it to when in a separate form (you don't have to read this;)? The following produces an almost empty webpage with just a submit button. The required action is only undertaken when the submit button is pressed: <form method="post" action=""> <input type="submit" name="x" value="> "> <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">"> </dtml-if> </form> Cheers, Dirk
dvl wrote:
Hello Andy
Must admit I cant be bothered to read all this but some notes:
<input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">>">
This is pointless, the page will never be rendered because it will instantly do the redirect. If you could refactor this a bit to more concise question...
Gosh, you're harsh. I'll try.
Why the instant redirection?
I want to make the redirection conditional on clicking the submit button.
Why _does_ it work as I'd like it to when in a separate form (you don't have to read this;)? The following produces an almost empty webpage with just a submit button. The required action is only undertaken when the submit button is pressed:
<form method="post" action=""> <input type="submit" name="x" value="> "> <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">"> </dtml-if> </form>
Cheers, Dirk
Dirk, what you wrote is right, albeit a quite convoluted way to do this. Let me rewrite this (ignore the wrapping): <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))"> </dtml-if> <form method="post" action=""> <input type="submit" name="x" value="> "> </form> You see, writing the dtml-call in the hidden action has no effect, it seems like you got irritated there. Could you perhaps reformulate what you want to do exactly? Why do you want a submit button (since you can, as you did, also use normal a hrefs to pass parameters with a GET request)? cheers, oliver
Hello Oliver,
Let me rewrite this (ignore the wrapping):
<dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">> </dtml-if>
<form method="post" action=""> <input type="submit" name="x" value="> "> </form>
Thanks
You see, writing the dtml-call in the hidden action has no effect, it seems like you got irritated there. ?? Irritated about my ignorance? Sure.
Could you perhaps reformulate what you want to do exactly? Why do you want a submit button (since you can, as you did, also use normal a hrefs to pass parameters with a GET request)?
I want submit buttons because they are supposed to be more intuitively recognisable for the user. Another reason is that I have a sort of horizontal navigation bar which should be able to handle a couple of redirections (page x images further, jump to a certain day) for which i seem to need forms anyway. Obviously I'm missing something (well, a lot). For instance, why does this work in a separate method:
<dtml-call "RESPONSE.redirect('toondecr?datum=%s&teller=%s' % (datum,teller))">>
and not in the method toondecr2 (which is a clone of toondecr with the submit form added)? Why can i display the dtml-var's 'datum' and 'teller' in the submit button: <input type="submit" name="x" value="<dtml-var datum><dtml-var teller>"> and yet get this error when clicking the submit button: Error Type: NameError Error Value: global name 'datum' is not defined Just can't figure why the variables ain't passed. Ah well, thanks a lot for your efforts. Have a nice weekend. Cheers, Dirk
dvl wrote:
Hello Oliver,
Let me rewrite this (ignore the wrapping):
<dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' %
(datum,teller))">>
</dtml-if>
<form method="post" action=""> <input type="submit" name="x" value="> "> </form>
Thanks
You see, writing the dtml-call in the hidden action has no effect, it seems like you got irritated there.
?? Irritated about my ignorance? Sure.
I sould have been more verbose. Of course, the dtml-call has an effect, namely the same independent from where it is written. It's just that writing it into the value attribute of the submit button doesn't give any extra functionality, like e.g. doing the call when the submit button is pressed.
[snip]
<dtml-call "RESPONSE.redirect('toondecr?datum=%s&teller=%s' %
(datum,teller))">>
and not in the method toondecr2 (which is a clone of toondecr with the submit form added)?
Why can i display the dtml-var's 'datum' and 'teller' in the submit button: <input type="submit" name="x" value="<dtml-var datum><dtml-var teller>"> and yet get this error when clicking the submit button: Error Type: NameError Error Value: global name 'datum' is not defined
Just can't figure why the variables ain't passed.
Well, the code I posted does work (tested), so I'm quite sure your name error appears somewhere else. Could you use the code I posted in your method - because it's less confusing IMO - and, if it doesn't work, post the whole source code. I'm sure we'll find the problem. cheers, oliver
Hello Oliver,
Of course, the dtml-call has an effect, namely the same independent from where it is written. It's just that writing it into the value attribute of the submit button doesn't give any extra functionality, like e.g. doing the call when the submit button is pressed.
If I use your code <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <dtml-call "RESPONSE.redirect('toondecr?datum=%s&teller=%s' % (datum,teller))"> </dtml-if> <form method="post" action=""> <input type="submit" name="x" value="ROEPTOON> "> </form> in a separate method, it does exactly that: the call is performed when and only if the submit button is pressed. When i use it in the method 'toondecr', and click on the submit button, I get Error Value: global name 'datum' is not defined What i want to do is the button equivalent of the link <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum)">">Next</a> (which works, in the method 'toondecr') I don't know if some kind of (quasi) recursion is at hand or if datum is not properly recognised as a DateTime string.
Well, the code I posted does work (tested), so I'm quite sure your name error appears somewhere else.
Yes, i suppose so. As it is, i've spent far too much time (which is running out for this project) on this issue and i'll revert to plain links for the time being. That is not to say i didn't pick up some good things from the efforts and your help for which thanks once more.
Could you use the code I posted in your method - because it's less confusing IMO - and, if it doesn't work, post the whole source code.
Well i'm afraid you got better things to do, but here it is. If you feel you'd have so see further coding, i'd gladly provide it. Thanks for your time, cheers, Dirk method 'toondecr' <dtml-var standard_html_header> <dtml-let navcaller=document_title> <dtml-var navbar> </dtml-let> <dtml-in "decrQuery(_.None, _, datum=(_.str(datum)))" size=1 start=teller> <dtml-call "REQUEST.set('totaal', _['count-datum'])"> <table width="100%" border=0> <tr> <td align=left valign="top" width="100%"> <dtml-if previous-sequence> <a href="<dtml-var "'toondecr?datum=%s&teller=1' % (datum)">" style="text-decoration: none;"><b> << </b>eerste </a> <dtml-else>  </dtml-if previous-sequence> </td> <td align=center valign="top" width="100%"> <dtml-if previous-sequence> <dtml-call "REQUEST.set('teller', _['sequence-number'])"> <dtml-call "REQUEST.set('teller', teller-1)"> <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum, teller)">" style="text-decoration: none;"><b> <</b> vorige </a> <dtml-call "REQUEST.set('teller', teller+1)"> <dtml-else>  </dtml-if previous-sequence> </td> <td align=center valign="top" width="100%"> <dtml-if next-sequence> <dtml-call "REQUEST.set('teller', _['sequence-number'])"> <dtml-call "REQUEST.set('teller', teller+1)"> <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum, teller)">" style="text-decoration: none;"><IMG SRC="vooruitbutton" ALT="vooruitbutton" WIDTH=30 HEIGHT= BORDER=0><b> </b> </a> <dtml-call "REQUEST.set('teller', teller-1)"> <dtml-else>  </dtml-if next-sequence> </td> <td align=right valign="top" width="100%"> <dtml-if next-sequence> <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum, totaal)">" style="text-decoration: none;"><b> >></b> laatste </a> <dtml-else>  </dtml-if next-sequence> </td> </tr></table> <table><tr> <td align=right valign="top" width="100%"> <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))"> </dtml-if> <form method="post" action=""> <input type="submit" name="x" value="> "> </form> </td></tr></table> <table width="100%"> <tr> <td align=left><dtml-var directory>/<dtml-var imagenaam></td> <td align=center>Decreet van <dtml-var datum></td> <td>image <dtml-var sequence-number> van <dtml-var totaal> voor deze dag</td> <td>p. <dtml-var bladzijde></td> </tr></table> <table width="100%"> <tr> <td align=center> <img src="http://192.87.107.12/dddimages/Decreet/Web/film01/<dtml-var imagenaam>.gif" alt="<dtml-var directory>/<dtml-var imagenaam>"> </td></tr></table> </dtml-in>
Dirk, I'm leaving the office now (far too late) and had just a very quick glance at your method, but perhaps I've spotted it. But I'll really follow up later if you tell me I was wrong: dvl wrote:
Hello Oliver, [major snippage]
Well i'm afraid you got better things to do, but here it is. If you feel you'd have so see further coding, i'd gladly provide it. Thanks for your time, cheers, Dirk
method 'toondecr'
<dtml-var standard_html_header>
<dtml-let navcaller=document_title> <dtml-var navbar> </dtml-let>
<dtml-in "decrQuery(_.None, _, datum=(_.str(datum)))" size=1 start=teller>
Why should this datum (in _.str(datum)) be known to zope? cheers, oliver
dvl writes:
... What i want to do is the button equivalent of the link <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum)">">Next</a> (which works, in the method 'toondecr') The button equivalent to this link is
<form action="toondecr"> <input type="hidden" name="datum" value="&dtml-datum;"> <input type="hidden" name="teller" value="&dtml-teller;"> <input type="submit" value="your button"> </form> Dieter
Hello Dieter,
What i want to do is the button equivalent of the link <a href="<dtml-var "'toondecr?datum=%s&teller=%s' % (datum)">">Next</a> (which works, in the method 'toondecr')
The button equivalent to this link is <form action="toondecr"> <input type="hidden" name="datum" value="&dtml-datum;"> <input type="hidden" name="teller" value="&dtml-teller;"> <input type="submit" value="your button"> </form>
Great, thanks ever so much. Cheers, Dirk
On Thu, 28 Mar 2002 07:14:28 +0100 dvl <dvl@wanadoo.nl> wrote:
Hello Andy
Must admit I cant be bothered to read all this but some notes:
<input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">>">
This is pointless, the page will never be rendered because it will instantly do the redirect. If you could refactor this a bit to more concise question...
Gosh, you're harsh. I'll try.
Why the instant redirection?
The redirection happens on the server the moment the page is rendered.
I want to make the redirection conditional on clicking the submit button. The the redirection needs to happen in the form processing method not in the form itself.
Why _does_ it work as I'd like it to when in a separate form (you don't have to read this;)? The following produces an almost empty webpage with just a submit button. The required action is only undertaken when the submit button is pressed:
Here you are doing the redirecting in the in the form itself after it get's called as a form processor.
<form method="post" action=""> <input type="submit" name="x" value="> "> <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">"> </dtml-if> </form>
Actually haven't looked at the other code, so perhaps I'm off. __Janko
Hello Janko,
Why the instant redirection? The redirection happens on the server the moment the page is rendered.
I want to make the redirection conditional on clicking the submit button. The the redirection needs to happen in the form processing method not in the form itself.
Here you are doing the redirecting in the in the form itself after it get's called as a form processor.
<form method="post" action=""> <input type="submit" name="x" value="> "> <dtml-if x> <dtml-call "REQUEST.set('datum', _.str('1796/03/11'))"> <dtml-call "REQUEST.set('teller', 5)"> <input type="hidden" name="" value="<dtml-call "RESPONSE.redirect('toondecr2?datum=%s&teller=%s' % (datum,teller))">"> </dtml-if> </form>
Sounds good and deep, too deep for me. I just can't translate <dtml-call "REQUEST.set('teller', _['sequence-number'])"> <dtml-call "REQUEST.set('teller', teller+1)"> <a href="<dtml-var "('toondecr2?datum=%s&teller=%s' % (datum,teller))">">link</a> into a form. Every time it seems like the form won't pass the variables. Well, i'll think some more about your comments. Thanks for responding. Cheers, Dirk
Gosh, you're harsh. I'll try.
Sorry, didnt mean to be ;)
Why the instant redirection?
The redirection is added to the HTTP headers for the response. The browser on seeing the redirect then redirects the user on to the next page, meaning they never actually see the page containing the redirect. Unless of course the RESPONSE.redirect only occurs on some condition... so looks like I was wrong, and didnt parse the dtml-if's correctly.
Why _does_ it work as I'd like it to when in a separate form (you don't have to read this;)? The following produces an almost empty webpage with just a submit button. The required action is only undertaken when the submit button is pressed:
Oliver points a better way in a post... so I wont take up any more time. taking-a-valium-ly-yours -- Andy
participants (5)
-
Andy McKay -
Dieter Maurer -
dvl -
Janko Hauser -
Oliver Bleutgen