SitePoint Sponsor |
|
User Tag List
Results 1 to 24 of 24
Thread: How to append input ?
-
Nov 6, 2008, 04:56 #1
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How to append input ?
Working with registration form. I need all the input remain if the form can not process due to missing field, or email and username provided are unvailable.
-
Nov 6, 2008, 05:02 #2
- Join Date
- Jun 2006
- Location
- Durban, South Africa
- Posts
- 287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How are you doing your vaildation?
If you are doing javascript validation then you would never have left the page and thus the information would still be there.
If you are doing some kind of server side validation (like php), then all your form variables would be in the $_GET or $_POST super global arrays, and you can thus access you variables like such
Code:$name_var = $_POST['name'];
You can then use that variable to populate the form, like so
Code:<form method="post" action="$_SERVER['php_self']"> <input type="name" value="<?php echo (isset($name_var) ? $name_var : ''); ?>" /> <input type="submit" /> </form>
-
Nov 6, 2008, 05:12 #3
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
HTML Code:<input type="name" value="<?php echo (isset($name_var) ? $name_var : ''); ?>" />
Is this a valid type in HTML form?
I would do like this:
- Submit the form to the same page.
Suppose I have a page mypage.php
PHP Code:<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(!empty($_POST['my_name']) && !empty($_POST['my_address'])){
# process your code further
# redirect to some page
}
# else the page will remain posted.
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="3261706071">
<title>Test</title>
</head>
<body>
<form action="" method="post" name="frmreg">
Name:<input type="text" name="my_name" id="my_name" value="<?php echo $_POST['my_name'];?>" />
Address:<input type="text" name="my_address" id="my_address" value="<?php echo $_POST['my_address'];?>" />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
</form>
</body>
</html>Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 6, 2008, 05:28 #4
- Join Date
- Jun 2006
- Location
- Durban, South Africa
- Posts
- 287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dope, my bad, well picked up there
This
Code:<input type="name" value="<?php echo (isset($name_var) ? $name_var : ''); ?>" />
Code:<input type="text" name="name" value="<?php echo (isset($name_var) ? $name_var : ''); ?>" />
You have implemented the logic correctly, it should work fine
-
Nov 6, 2008, 06:14 #5
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:<form method="post" action="$_SERVER['php_self']">
What does this $_SERVER['php_self'] do ?
-
Nov 6, 2008, 07:33 #6
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 6, 2008, 07:38 #7
- Join Date
- Jun 2006
- Location
- Durban, South Africa
- Posts
- 287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What does this $_SERVER['php_self'] do ?
-
Nov 6, 2008, 10:34 #8
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Make sure to run $_SERVER['PHP_SELF'] through htmlspecialchars() otherwise you risk xss attacks. Same goes for when you echo the variables back into the form fields.
-
Nov 6, 2008, 11:03 #9
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok, when i put that in form action, run the page. An error message "$_SERVER['PHP_SELF'] is not available in your system or site" something like that.
I will try again and get the correct message post here
-
Nov 6, 2008, 11:06 #10
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 6, 2008, 11:07 #11
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's a PHP variable so you need to wrap it in PHP tags:
Code:<form method="post" action="<?php echo $_SERVER['php_self']; ?>">
Pawel Decowski (you should follow me on Twitter)
-
Nov 6, 2008, 11:11 #12
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pawel Decowski (you should follow me on Twitter)
-
Nov 6, 2008, 11:38 #13
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 6, 2008, 12:11 #14
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's not defined by HTML specification thus it cannot be guaranteed that every browser will behave like this. Of course it may work but we should adhere to standards. As to why validator doesn't issue an error (or warning) -- that's a question for the W3C. I can only speculate that the reason is that the standard doesn't specifically require a URI, it only says that "behavior for a value other than an HTTP URI is undefined". In other words HTML specification doesn't say what the browser should do when the value isn't a URI.
http://www.w3.org/TR/html401/interac...ml#adef-action
EDIT: Actualy HTML4 specification does require a URI as a value of action attribute.Pawel Decowski (you should follow me on Twitter)
-
Nov 7, 2008, 13:49 #15
- Join Date
- Jun 2007
- Location
- Finland
- Posts
- 20
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
According to the HTML specification, the data type for the action attribute is uri, and the Basic HTML data types page then says that the specification uses the term URI as defined in RFC 2396. Here's a quote from the RFC:
4.2. Same-document References
A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document. Traversal of such a reference should not result in an additional retrieval action. However, if the URI reference occurs in a context that is always intended to result in a new request, as in the case of HTML's FORM element, then an empty URI reference represents the base URI of the current document and should be replaced by that URI when transformed into a request.int main()
{
// No pun indented.
}
-
Nov 7, 2008, 14:11 #16
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Although it has to be there, in XHTML Strict validation anyway (and who ISN'T using at least XHTML transitional by now?)
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Nov 7, 2008, 14:20 #17
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's clear that HTML4 specification does require action attribute to be a URI. It's too bad the specification is so ambiguous. Stating that "behavior for a value other than an HTTP URI is undefined" doesn't help at all. But it's been a long known fact that HTML specification is full of such ambiguous statements.
EDIT: HTML5 is looking better, but it's still missing loads of points I would like to see clearly specified.Disabled attribute for option elements being at the top of my list. It seems the specification has changed since I last checked. I'm really glad.Pawel Decowski (you should follow me on Twitter)
-
Nov 11, 2008, 07:53 #18
- Join Date
- Dec 2004
- Location
- Sweden
- Posts
- 2,670
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 11, 2008, 08:08 #19
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pawel Decowski (you should follow me on Twitter)
-
Nov 11, 2008, 10:45 #20
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 15, 2008, 04:04 #21
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how about doing this with select and radio ?
-
Nov 15, 2008, 22:19 #22
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 16, 2008, 04:54 #23
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
append chosen radio option and select option.
Basically, in previous discussion we echo the data to the value attribute of text field/input to append it.
But radio button and menu/list need to have their own value at all time, so I don't think of how could I append it.
-
Nov 16, 2008, 06:24 #24
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Yeh, I've started using HTML strict again recently. XHTML isn't supported by IE, and I've been swayed by the arguments on here (I like the XHTML syntax, but HTML is more practical / correct until the problems with XHTML are sorted out.. and even then it won't be suitable for a lot of applications). I may convert some of my existing sites to HTML strict as well.
Bookmarks