The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> choose if to load hidden input or not
metalball
post Dec 13 2009, 12:13 PM
Post #1


Newbie
*

Group: Members
Posts: 15
Joined: 21-November 09
Member No.: 10,395



hi,
I have a weird question...
I have a form with multiple submit buttons, and I'm looking for a way to load some hidden inputs
only if one of the submits clicked. in any other case, I don't want the hidden input to appear at the
generated code at all.

how can it be done?

thanx

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Dec 13 2009, 01:20 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Since you say "generated code", I assume the page the user goes to after submitting the form is generated by the script on the server that handles the form? Then make that script write different versions depending on which button is clicked.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
metalball
post Dec 13 2009, 01:47 PM
Post #3


Newbie
*

Group: Members
Posts: 15
Joined: 21-November 09
Member No.: 10,395



QUOTE(pandy @ Dec 13 2009, 08:20 PM) *

Since you say "generated code", I assume the page the user goes to after submitting the form is generated by the script on the server that handles the form? Then make that script write different versions depending on which button is clicked.


i have 1 text input and multiple submit options. for some of those submits i want to use hidden inputs, but for the others i don't want them.
i'm having this mixup in 1 file, in my case 1 php file, but the code is html:

CODE
<form>
<input type="hidden"/>
<input type="text"/>

<input type="submit1"/>
<input type="submit2"/>
</form>

now lets say that i want to use the hidden input only when i press submit1, so i need somehow to "hide" the hidden input from the html until submit1 pressed.
i don't have any script yet, its just html there. by rendered code i ment the html page in the browser.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Dec 13 2009, 02:12 PM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



OK, I misunderstood. But the script on the server is still where things have to happen. You have to write it so the hidden values are used only if the right button is clicked.

This isn't my bag of tea really, but I don't see how you can avoid doing it server side. You could probably have JavaScript catch the click and add a hidden input and then submit the form, but then the whole form would depend on JS and that's a big no-no.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
metalball
post Dec 13 2009, 02:26 PM
Post #5


Newbie
*

Group: Members
Posts: 15
Joined: 21-November 09
Member No.: 10,395



QUOTE(pandy @ Dec 13 2009, 09:12 PM) *

OK, I misunderstood. But the script on the server is still where things have to happen. You have to write it so the hidden values are used only of the right button is clicked.

This isn't my bag of tea really, but I don't see how you can avoid doing it server side. You could probably have JavaScript catch the click and add a hidden input and then submit the form, but then the whole form would depend on JS and that's a big no-no.

i've tried to do some JS to add the hidden inputs onclick or even onmouseover,
but the problem was to place the hidden inputs BEFORE the text input in the HTML.

i'm not trying to avoid JS, i just couldn't find the right way to do so, thats why i've posted here...

i even thought of making php function that simply echoes the hidden input... but i couldn't call it onclick or onmouseover...
and i can't figure out how to place it before the text input...

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Dec 13 2009, 06:40 PM
Post #6


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



I'm not good at inserting elements with JS, but for someone to be able to help you out you need to post more of the HTML, preferably a link to a sample page. Christian usually knows how to do this kind of stuff.

I still think it's a bad idea to do this client side, but it's your show.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 13 2009, 07:37 PM
Post #7


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Dec 13 2009, 08:12 PM) *

But the script on the server is still where things have to happen. You have to write it so the hidden values are used only if the right button is clicked.

Yes, why not submit the hidden INPUT? The server-side script doesn't have to do anything with it if you don't want it to.

Or is this a special case where you e.g. don't have access to the server-side script? unsure.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
metalball
post Dec 14 2009, 03:20 AM
Post #8


Newbie
*

Group: Members
Posts: 15
Joined: 21-November 09
Member No.: 10,395



QUOTE(Christian J @ Dec 14 2009, 02:37 AM) *

QUOTE(pandy @ Dec 13 2009, 08:12 PM) *

But the script on the server is still where things have to happen. You have to write it so the hidden values are used only if the right button is clicked.

Yes, why not submit the hidden INPUT? The server-side script doesn't have to do anything with it if you don't want it to.

Or is this a special case where you e.g. don't have access to the server-side script? unsure.gif


submitting the hidden input mess up my output url. like i said, the user on submit is redirected to external url, and submitting unwanted hidden inputs makes the url messy... i wanted to have different submit for each option, with its own hidden inputs if necessary.
anyway i've looked for some way to make it simple, but the solution seems to be in server side...

the problem is that i wanted to redirect user on submit DIRECTLY to the external url,
and when inserting server side script, like sending the form action through php file, the "latency" of getting the final url is bigger.
and if my user is far from my host server, his latency to the final url is higher then if redirected on submit.

This post has been edited by metalball: Dec 14 2009, 03:22 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 14 2009, 05:27 AM
Post #9


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(metalball @ Dec 14 2009, 09:20 AM) *

the user on submit is redirected to external url, and submitting unwanted hidden inputs makes the url messy...

Aha! cool.gif

You might "hide" the query string by using method POST instead of GET.

Or you might use GET and submit the form to a "jumper" page (on your own server), that strips out the hidden INPUT part of the query string and then redirects to the external URL.

Or you might submit the form without any hidden INPUT fields, and add that part of the query string on the jumper page (depending on submit button used).

QUOTE
the problem is that i wanted to redirect user on submit DIRECTLY to the external url,
and when inserting server side script, like sending the form action through php file, the "latency" of getting the final url is bigger.
and if my user is far from my host server, his latency to the final url is higher then if redirected on submit.

The delay from using a jumper page should be a minor problem compared with using javascript.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
metalball
post Dec 14 2009, 06:15 AM
Post #10


Newbie
*

Group: Members
Posts: 15
Joined: 21-November 09
Member No.: 10,395




there is a problem with what your suggestion.

nevermind which method i'm using, there are some submit options that must have the hidden inputs placed before the text query at the url:

http://somedomain.com/index?hidden=something&q=query

to achive this, the code at the html must be
CODE
<form>
<input type="hidden" value="something" name="hidden"/>
<input type="text" name="q"/>

<input type="submit"/>
</form>


if i make:
CODE

<form>
<input type="text" name="q"/>
<input type="hidden" value="something" name="hidden"/>
<input type="submit"/>
</form>

or
CODE

<form>
<input type="text" name="q"/>
<input type="submit"/>
<input type="hidden" value="something" name="hidden"/>
</form>


the output will be:
http://somedomain.com/index?q=query&hidden=something

which i don't want.

if i'm using JS to call function that creates hidden input onclick or onmouseover, the hidden input will be placed after the text query.


about the jump page, that what i'm using now. i've created a php jump page, the process looks like this:
CODE
<form action="some.php">
<input type="text" name="q"/>
<input type="submit"/>
</form>


CODE
//some.php
<?php
$q=_GET["q"];
header:(Location: 'http://somedomain.com/index?hidden=something&q='.$q);
?>



but it does effects latency! and if user far from host, while first redirected to the some.php page, and then to external url,
the latency is twice bigger then direct link to external url.

This post has been edited by metalball: Dec 14 2009, 06:16 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 14 2009, 09:37 AM
Post #11


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(metalball @ Dec 14 2009, 12:15 PM) *

if i'm using JS to call function that creates hidden input onclick or onmouseover, the hidden input will be placed after the text query.

If you've created the INPUT element with the DOM you can use the insertBefore() method to place it before the text field. See http://www.quirksmode.org/dom/w3c_core.html

Or you could use a hidden INPUT by default, and instead remove it with JS. That might also keep the form functional for users without JS (they would submit the hidden field with both submit buttons, though).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th April 2024 - 04:20 AM