473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Webprogr: Link with automatic submit

Hi,

As I am no expert web programmer I thought I'd better ask the experts if
there is a simpler or better solution to my problem than the one I am
thinking of. (using TurboGears)

The problem
-----------

I have a form. Ok. you can submit, validate it etc.
Now I have a link on that form to another page.
What I want is that the form gets automatically submitted and validated
before the browser follows the link. If the validation has errors the
link should not be followed.

My solution
-----------

1. client side solution

First I thought I just make a little javascript function like this:

function xy(url) {
document.form.submit();
parent.location=url;
}

The problem is that submit works ansynchronisly. I do not get a return
code to decide if to follow the url or not. Furthermore the form does
not get submitted if there is the line parent.location=url; .

2. server side solution

I thought of including a hidden field and include directives for my
controller method to raise the redirection if no validation errors are
there.

<a href="#" onClick="xy('/somewhere')"></a>

function xy(url) {
document.form.hiddenfield.value = "redirect_to: " + url;
document.form.submit();
}

@expose
def mycontroller(self, *args, **kwargs):
#do the usual saving stuff

if hasattr(kwargs, 'hiddenfield'):
#parse the JSON or mini-langage and do the redirection, when no
#validation errors
As there might be more other directives necessery for client-server
communciation I thought of setting the hiddenfield value to JSON or a
self made mini-language and parse this in the controller.

Is this a good solution?
Are there any other options?

--
Greg

Oct 20 '06 #1
2 1321
Gregor Horvath wrote:
Hi,

As I am no expert web programmer I thought I'd better ask the experts if
there is a simpler or better solution to my problem than the one I am
thinking of. (using TurboGears)

The problem
-----------

I have a form. Ok. you can submit, validate it etc.
Now I have a link on that form to another page.
What I want is that the form gets automatically submitted and validated
before the browser follows the link. If the validation has errors the
link should not be followed.

My solution
-----------
(snip)
Are there any other options?
<OT>
yes : replace the link with another submit button, then in your
controller check which submit has been successful and take appropriate
action.

Links are for GET request (which are supposed to be idempotent), and are
definitively *not* supposed to issue (even if indirectly) a POST request.
</OT>

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 20 '06 #2
Bruno Desthuilliers schrieb:
yes : replace the link with another submit button, then in your
controller check which submit has been successful and take appropriate
action.
Thanks !

--
Servus, Gregor
Oct 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: shake | last post by:
I have to develop an application sounds like this:- User is allow to access a form (is actually a test/quiz) within a specific time frame, let say 45 minutes. After this 45 minutes, if the user...
12
by: Terry | last post by:
I'm trying to automatically submit a form to another ASP page after some <input> fields values are filled by ASP. I know I can do it using javascript, but is there a way to automatically submit...
4
by: Dodo | last post by:
Is it possible to create a link that can post a value to an ASP page without java?
1
by: Stanimir Stamenkov | last post by:
Here's an example: <form action="bogus" method="post"> <p> <a href="prev.cgi"><input type="submit" name="prev" value="< Back"></a> <a href="next.cgi"><input type="submit" name="next"...
5
by: J | last post by:
Hi All, I have a quick question, I am making a little script that shows users how easy it is to have there clipboards read. I would like to capture my users clipboard (plain text only) and then...
1
by: Piotr Kurpiel | last post by:
Hi, I am creating a site where I need to refer to another external file (aspx). I create the form and works fine. But as soon as I try to submit the form automatically (with form.submit()) I get...
26
by: Mica Cooper | last post by:
Hi, I need to pass some info in a javascript submit. <a href="javascript:document.formName.submit();">Submit Form</a> Normally a link would do page.jsp?x1=1&x2=2&x3=3 and you would pull x1,...
4
by: kschneider | last post by:
Assume there's a form with it's action attribute all set to post to a URL, but without a submit control. Form submission is done via a link and I want to prevent the classic "double submit"....
4
ganesanji
by: ganesanji | last post by:
Hi, I have written a simple php coding for getting the name , phone number and insert the values into data base. My problem is that when ever I just click the refresh button in the browser...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.