Jump to content

[SOLVED] keeping the page state FORMS


thosecars82

Recommended Posts

Hello there

I wanted to ask you this: I have a get variable in the url which indicates the language in which a website is shown.Moreover, there is a form with a text area which loses its content when the language is changed because I am not keeping any get or post variable with the content of that text area. For that reason, I wanted to learn some way to keep the state of the content of the text area so that the user can still see the text that they wrote when they changed the language of the website. You can check what I mean if you write anything in the text area of the contact section of www.metatradersoftware.com and change the language before clicking send. As you will see, the content of the text area will be lost.

I would appreciate any idea to keep that content.

Thanks in advance

Link to comment
Share on other sites

When should we use a get variable in the url to convey information instead of a session variable

 

when you need to change a value without submitting a form. for instance, if a user is looking at a list of records, each record may link to a detail page. that link will need to carry the id of the record in the URL. (there are other ways of doing it, but GET is the simplest.)

Link to comment
Share on other sites

you could make your language link a submit button instead and have the text area carry over as a posted value.  setup a condition in your script to check whether it was the language "post" button pushed or the real submit button.

Ok Crayon

I understand what you suggest. But I want to say this. Doing it the way I understand you mean, would imply to put an absolute position for the text area to be able to place it far away from the language link.

 

            Since in this particular case I just have one text area, this choice might not be bad. But let's say that I had a really complex page with lots of text areas in different places of the layout. Moreover, I might have other objects different to text areas(I do not know which ones to say right now). Anyways, if I had several objects for which I should keep the state, then, putting them all in the same form and all of them having absolute positions would not be a very good solution I guess. Tell me if I am wrong but I do not think that using a lot of absolute positioned objects makes a good design.  What alternative would we have in that case? Would we be forced to use javascript? It's not that I do not want to use it but since I have heard that there are some people who still do not hava javascript enabled on their pcs, I thought of avoiding the use of javascript as much as possible using php instead.

 

What do you think about all this?

Thanks in advance

 

Link to comment
Share on other sites

I think you are absolutely right, thosecars.  It would be horrible design.  I offered an alternative to using javascript, because you're looking for alternatives.  That's really about the only thing you can do, as far as changing it on the fly like that, using just php. 

 

Honestly, I'd advise you to go the javascript route.  Yes, there are *some* people that still have js disabled on their pcs, but they are so few and far between these days in the world of ajax and "web 2.0" that you should probably sit down and think about whether those very few paranoids out there would really hurt your business/org/whatever, by not being able to change languages on the fly and yet keep their text area info.

 

My opinion is that you're designing a feature here.  A feature, not an integral part of your system.  I really don't think it's that big a deal to have the javascript.  I personally think that under (most) normal circumstances, people would go to your site, and clicking the language of their choice would be the first thing they do.  I really don't see a whole lot of people suddenly deciding to switch from English to French in the middle of their surfing while they are filling out a contact form. 

 

My 2 Cents.

Link to comment
Share on other sites

When sending information through the post method, using a form is always the best available option?

I mean, let's say that the information you want to convey is just the state of the page just to avoid losing that state. Thus, you do not want that this form you use for the post method is seen except may be the submit button. Therefore, you will set all the elements of the form except the submit button as invisible may be by putting an absolute position to them which might be positioned absolute like left:-2000px or so. That would avoid anyone from seeing the information on the form. Is this the most standard, common and straightforward way to save the state of a page in general?

Thanks in advance

Link to comment
Share on other sites

In order to get your browser to make a request to the server, you have to have it submit a request via the POST method or the GET method.  As far as I know (I admit I'm not an expert), those are you only options.  Now, you could look into using Ajax, but as you probably already know, Ajax uses the post/get method just the same, as well as javascript. 

 

Overall, I think I'm not entirely sure what you're asking there in that last post... can you rephrase? Are you wanting to go for making the language link a submit form now?

 

Link to comment
Share on other sites

What I meant was this:

Let's say I want to link another page without losing the content of 5 text areas each of them in different forms I might have in my page. Then if I click the submit button of one of the forms, this would link to another page. Nonetheless, I would not want to lose the content of the 4 text areas which are on the other 4 forms different from the one whose button I clicked. How can I keep the content of all the text areas if they are in different forms? That was my question.

 

Now another question:

now I am trying to read the content of a text area whose id is idcomentarios to be able to send it by post method to the server. The code is this:

 

...

<?php

$state = "?send=0";

if (isset($_GET['send']))

$state = "send=" . $_GET['send'];

if ($language=='en')

{

echo '<FORM id=\'intermedio\' action=\''.$pagina.'?' . $state.'&language=sp'.'\' method=\'post\'>';

echo '<P>';

echo '<INPUT class = \'enlacespanishflag\' type=\'submit\' value=\'';

echo _(" ") . "'>";

echo '<TEXTAREA id=\'comentariosintermedios\' rows=\'10\' cols=\'10\'>';

?>

<script type="text/javascript">

<!--

var txt = document.getElementById('idcomentarios').value;

document.write(text);

//-->

</script>

<?php

echo '</TEXTAREA>';

echo '</P>';

echo '</FORM>';

....

 

Now, what I see in the text area with id comentariosintermedios is just this:

<script type="text/javascript">

<!--

var txt = document.getElementById('idcomentarios').value;

document.write(text);

//-->

</script>

Nevertheless, what I expected to see was what it was written in the content of the text area with id 'idcomentarios'. Any idea to get the real content of the text area?

Link to comment
Share on other sites

cleaned up the code some.  Not sure what you are wanting, but maybe this will help someone else fix the problem:

<?php
               $state = "?send=0";
               if (isset($_GET['send']))
                  $state = "send=" . $_GET['send'];   
               if ($language=='en')
                  {   
                  	echo<<<END
				<FORM id="intermedio" action="$pagina?$state&language=sp" method="POST">
                  		<p>
                  		<input class="enlacespanishflag" type="submit" value="">
                  		<TEXTAREA id="comentariosintermedios" rows="10" cols="10">
                  		 <script type="text/javascript">
             				<!--
               				var txt = document.getElementById('idcomentarios').value;
               				document.write(text);
             				//-->               
               			</script>
               			</TEXTAREA>
               			</p>
               			</FORM>
END;

}

Link to comment
Share on other sites

I guess that the question relative to the code would be answered like this:

that javascript code

<script type="text/javascript">

            <!--

              var txt = document.getElementById('idcomentarios').value;

              document.write(text);

            //-->             

              </script>     

which is in the content of a textarea gets returned to the browser like text instead of being interpreted like javascript. May be, if I had put the javascript outside the textarea, it might have worked by really writing the text string with document.write(text).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.