Reload menu selection in form
Moderator: General Moderators
Reload menu selection in form
Hello all,
I am new to this forum so salutations to all.
I searched for this answer and could not find the specific answer and I know I have seen this answer somewhere but cannot put my eyes on it. And for the life of me, I cannot get my brain to come up with the answer ... but I know it is simple. After an error check page of a form with a menu item in it, how does one reload the users selection (assuming they had made one) when the form is reloaded? I know how with the regular input fields but am brain dead on this one.
Thanks in advance.
Dave
I am new to this forum so salutations to all.
I searched for this answer and could not find the specific answer and I know I have seen this answer somewhere but cannot put my eyes on it. And for the life of me, I cannot get my brain to come up with the answer ... but I know it is simple. After an error check page of a form with a menu item in it, how does one reload the users selection (assuming they had made one) when the form is reloaded? I know how with the regular input fields but am brain dead on this one.
Thanks in advance.
Dave
- devork
- Forum Contributor
- Posts: 213
- Joined: Fri Aug 08, 2003 6:44 am
- Location: p(h) developer's network
one thing that I used to avoid sessions was
I made a hidden field and populated that field with the unique letter separater with Javascript when user clicks the value is added and then explode them and repopulate them in case anything is wrong.
if you have many category data then you have to make more hidden fields and process ....
I made a hidden field and populated that field with the unique letter separater with Javascript when user clicks the value is added and then explode them and repopulate them in case anything is wrong.
if you have many category data then you have to make more hidden fields and process ....
That seems about as involved to me as using sessions. Sessions arn't that hard so it would probably be as useful to put the values there. As it turns out, I seem to be able to keep the value because it is only being kept over a single page and I have used the statement <? $_POST['fieldvalue']; ?> in the form. However, I could not find a way to place this statement in the menu code in the form but it seem to retain the value anyway after returning from the error page.
Not sure if any of this made sense but thanks all for your replys.
Dave
Not sure if any of this made sense but thanks all for your replys.
Dave
If I understood you correct...
A javascript that goes page history-1 combined with this...
...to block naste IE bug perhaps?
The snippet above so that the form is not cleared upon returning to the former page.
Run this and press the back key once. I'm not using javascript in this example (you might not need it either) but it might give you some ideas.
A javascript that goes page history-1 combined with this...
Code: Select all
header("Cache-control: private");The snippet above so that the form is not cleared upon returning to the former page.
Code: Select all
<?php header("Cache-control: private"); ? > // this board cant handle this correct, added space...
<form method="post">
<select name="foo">
<?php
for ($i=1;$i<=22;$i++) {
echo '<option>'.$i.'</option>';
}
? > // this board cant handle this correct, added space...
</select>
<input type="submit">
</form>- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Take a look to a Code Snippet I post just right now: PHP/HTML: Print <select><options></select>. Hope it helps!filch wrote:Yes ... but what if the item is a menu? How do you recall what the user had selection (option value)?
Cheers,
Sco.
OK .. I understand what you are doing is creating a select form list with PHP. Again, my question is .. if the person makes a mistake and the script generates an error page, and then the user clicks on the back button or a javascript history-1 link, in a normal form element (non menu) I could use $_POST['fieldname'] or $_REQUEST['somefieldname'} to repopulate the form with the user's values so they would not have to start from scratch. BUT .. how would I do that with the menu element?
filch
filch
tricky
If it is a selfproccessing form, you could call up the value of each form element as the initial value. ie
If somebody just arrives on the page, there will be nothing in the fields, after they enter stuff and submit the form, when it refreshes the entries should hold the values the user entered.
Hope this is what you where looking for.
Code: Select all
<input type="text" value="<?php echo $_POST['fieldvalue']; ?>">Hope this is what you where looking for.
1) Best to post the form to itself. Example, at the top of your page, do a
If it is not correct and you want to populate the form with the current answers ... do as mentioned above ... in your input tags, use
To rechoose an option / drop down box, do this
By it being selected, then it will rechoose that option. By pressing the back button, I don't know if it will still recall the choices .. or with any form .. php or not.
For some reasons the examples above are not showing the closing php tags \?> ..
Code: Select all
if($_POST['submit'] == "submit") {
// do your form checking
// if something is not right or empty , change the submit value
// if correct, process form
} else {Code: Select all
value="<? print "$input_name"; ?>Code: Select all
<select name="name">
<option value="2" <? if($name == '2') { print "selected"; } ?>>
<option value="3" <? if($name == '3') { print "selected"; } ?>>
<option value="4" <? if($name == '4') { print "selected"; } ?>>For some reasons the examples above are not showing the closing php tags \?> ..
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA