SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: Keeping Info in a Form
-
Oct 7, 2007, 17:09 #1
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Keeping Info in a Form
Hey,
So I have a form where it redirects you to a error page if you missed a field.
The problem with this is, that it clears all the fields that you did type in. So I want it to carry these fields over to the error page, even if some are missing.
Here's some of the code in my form to help you see how I'm doing this...
Code:$name = $_POST['name']; $email = $_POST['email']; $sex = $_POST['sex']; $security = $_POST['security']; $comments = $_POST['comments'];
Code:if (!empty($errors)) { header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors))); exit; }
Basically I can check if they entered something other then the default value and pass that through in the url. Then read it back on the error page from the url. I'm just not sure how I could achieve this.
I'm going to go and try to figure it out, but if anyone can help that'd be awesome.
Thanks,
Mario$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:01 #2
- Join Date
- Oct 2007
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi there, my 1st post here.
About your problem, you can put your html to point to the same page. Here you just check if something was submitted.
PHP Code:<?php
//stuff ...
if( isset($_POST[name]) ){
// check for stuff here
}else{
?>
<!--put html here-->
<form action=""...
<input name="name" value="<?=$_POST['name']?>" />
....etc
<!-- end html :) -->
<?php
}
?>Last edited by andr; Oct 7, 2007 at 18:18. Reason: errored explanation
-
Oct 7, 2007, 18:09 #3
- Join Date
- Dec 2002
- Location
- Canada
- Posts
- 2,476
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Rather than redirecting on error, why not just submit to the same page then just store into $error. Then you still have all submitted fields that you can put into the form fields' value attribute
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter
-
Oct 7, 2007, 18:16 #4
- Join Date
- Oct 2007
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yup, triexa is right. You can add an $error variable and then juggle with it
I hope it helps. If you still have trouble tell us.
-
Oct 7, 2007, 18:17 #5
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the replies guys.
Thats a good point, I throw in a new div on top when theres an error stating what error happened. I guess I just can't figure out how to keep that on the same page.
Thanks,
Mario
I'm basically trying to do this...
1. Check if the name field is not blank or the value within does not equal Name.
2. If it passes the first test, pass the value contained in $name to the url on the error page. So then I could just pull it from there and fill the field in.
Here's the code I'm using but it doesn't seem to be working.
Code:if (!empty($name)) { $saved_name = $name; }
Code:if (!empty($errors)) { header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors))) . "&name=" . urlencode($saved_name); exit; }
Thanks,
Mario$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:19 #6
- Join Date
- Oct 2007
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
before if (!empty($name)) {
put this: $name = $_POST['name'];
-
Oct 7, 2007, 18:20 #7
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i have all that just above that code...
Code:$headersep = (!isset($check) || (check == 0))?"\r\n":"\n"; $name = $_POST['name']; $email = $_POST['email']; $sex = $_POST['sex']; $security = $_POST['security']; $comments = $_POST['comments']; $http_referer = getenv("HTTP_REFERER");
Thanks,
Mario$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:20 #8
- Join Date
- Oct 2007
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
also before that you should check if( isset($_POST['name']))
-
Oct 7, 2007, 18:21 #9
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe it'll help if you guys see the form, you can find it here...
http://zenit.senecac.on.ca/~dma322_073b13/Basic_Form$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:22 #10
- Join Date
- Oct 2007
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ooww
simultaneous posting...
you can call that function with the parameters $name, $sex, etc. or you can make those vars globals
-
Oct 7, 2007, 18:23 #11
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
name will always be set, cause it has a default value of Name in it.
So i can use...
Code:if (!empty($name) || ($name != Name)) { $saved_name = $name; }
$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:23 #12
- Join Date
- Dec 2002
- Location
- Canada
- Posts
- 2,476
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, do you have something like $name = $_POST['name']?
As for "same page" something like:
Code:<? if ($_POST) { if ($_POST['name'] != 'Kaitlyn') $error = 'You did not enter a good enough name'; } if (isset($error)) { echo '<div style="color:#FF000; font-weight:bold">' . $error . '</div>'; } ?> <form action="this_script.php" method="post"> Your name: <input type="text" name="name" value="<?=$_POST['name']?>" /> <input type="submit" value="Submit" /> </form>
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter
-
Oct 7, 2007, 18:25 #13
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sweet triexa, I'm going to try to use that code right now to cur off the error page.
Thanks
Anyone on the other problem? :-P$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 18:35 #14
- Join Date
- Dec 2002
- Location
- Canada
- Posts
- 2,476
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter
-
Oct 7, 2007, 18:43 #15
- Join Date
- Jul 2003
- Location
- Toronto, Ontario
- Posts
- 234
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey,
Thanks for trying guys,
Let me try to make the question super simple to understand cause we've gotten a bit off track.
Code:if (!empty($errors)) { header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors))); exit; }
I tried...
Code:if (!empty($errors)) { header("Location: feedback_error.php?errors=" . urlencode(implode(", ", $errors)) . "&name="); exit; }
Any ideas?
Thanks,
Mario$ Available For Hire
Need a website designed or coded? Then feel free to contact me!
PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net
-
Oct 7, 2007, 21:15 #16
- Join Date
- Dec 2002
- Location
- Canada
- Posts
- 2,476
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't understand why you've gone back to the redirect on error, and then try to pass all the data back in the URL...
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter
Bookmarks