Help me code in php: very urgent
Moderator: General Moderators
-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
Help me code in php: very urgent
Hello frinds,
i have a form in which 30 fields are there. i. e name, age, date of birth....
problem 1) when i click on submit button and if there is an error in 20th field ...the form will clear all the values and agian i have to enter all 30 fields.
for this i am using value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; in input tag like
<label>4(a). First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>"><br><br>
but the problem here is when all the entries are correct and data is submitted then also the first name and others value will be remain in the same page.........the form will not clear out.
?????? anybody know the alternate way to have the fileds on the form when i refresh or submit the form
problem 2)
do anynbody know how to clear form when i am using value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; on every input to store the value on the form.
problem 3) i am having some select list say code list.....suppose it contains 3 values (1,2,3).........when i click on submit button and there is a error in some field or when refresh the form is resetting the its value
?????? can anybody tell me how to be with the same option (say option 3) when i do the above operation
thank you
i have a form in which 30 fields are there. i. e name, age, date of birth....
problem 1) when i click on submit button and if there is an error in 20th field ...the form will clear all the values and agian i have to enter all 30 fields.
for this i am using value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; in input tag like
<label>4(a). First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>"><br><br>
but the problem here is when all the entries are correct and data is submitted then also the first name and others value will be remain in the same page.........the form will not clear out.
?????? anybody know the alternate way to have the fileds on the form when i refresh or submit the form
problem 2)
do anynbody know how to clear form when i am using value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; on every input to store the value on the form.
problem 3) i am having some select list say code list.....suppose it contains 3 values (1,2,3).........when i click on submit button and there is a error in some field or when refresh the form is resetting the its value
?????? can anybody tell me how to be with the same option (say option 3) when i do the above operation
thank you
-
SimonMayer
- Forum Commoner
- Posts: 32
- Joined: Wed Sep 09, 2009 6:40 pm
Re: Help me code in php: very urgent
The way to do this is to force the page to redirect to itself after you have done what you need to do, but before creating the HTML.om.bitsian wrote: but the problem here is when all the entries are correct and data is submitted then also the first name and others value will be remain in the same page.........the form will not clear out.
?????? anybody know the alternate way to have the fileds on the form when i refresh or submit the form
u
Use:
Code: Select all
header("Location: index.php");I'm afraid I'm not able to look into the other problems you have at present but
Code: Select all
value="<?php if (isset($_POST['submit'])) echo $_POST['fnam'];Code: Select all
value="<?php if (isset($_POST['submit'])){ echo $_POST['fnam']; } ?>"Code: Select all
value="<? echo $_POST['fnam']; ?>"-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
Re: Help me code in php: very urgent
no what i just want is when all entries are correct and i press submit button it should clear the form showing messge "Data entered successfully. The PSRN generated is ",$psrn." " but the form is not clearing the fields....
suppose if i remove value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>" from the input value first name than every time i have to enter first name and other values if there is a error in any field of the form.......in my form around 30 entries are there so its difficult to write all entries again and again ....because i am testing all my fields(validation)
suppose if i remove value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>" from the input value first name than every time i have to enter first name and other values if there is a error in any field of the form.......in my form around 30 entries are there so its difficult to write all entries again and again ....because i am testing all my fields(validation)
Re: Help me code in php: very urgent
The proper way of doing things is not to echo anything from $_POST or $_GET. You should be putting the value into a different variable that you work with and echo back to the form... eg
If you were doing that then you could do unset the value if the form completes successfully. eg
Code: Select all
$f_name = htmlentities($_POST['name']);
if (empty($f_name)) { $error = "Name was missing."; }
echo "<input type=\"text\" value=\"".$f_name."\">";
Code: Select all
if (!empty($psrn)) {
$f_name = '';
}-
SimonMayer
- Forum Commoner
- Posts: 32
- Joined: Wed Sep 09, 2009 6:40 pm
Re: Help me code in php: very urgent
Using header("Locate: "); will clear the form down, as it will redirect you to the same page and lose the $_POST variables.om.bitsian wrote:no what i just want is when all entries are correct and i press submit button it should clear the form showing messge "Data entered successfully. The PSRN generated is ",$psrn." " but the form is not clearing the fields....
suppose if i remove value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>" from the input value first name than every time i have to enter first name and other values if there is a error in any field of the form.......in my form around 30 entries are there so its difficult to write all entries again and again ....because i am testing all my fields(validation)
To create the message, you would probably be best off using session cookies. See: http://www.php.net/manual/en/function.session-start.php
-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
Re: Help me code in php: very urgent
friends i am new in php
can u please explain me how should i use your code ....this is the code i am using for first name
<label>4(a). First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>"><br><br>
then
$fnam=($_POST['fnam']);
if(strlen($fnam)>10 || strlen($mnam)>10 || strlen($lnam)>10)
{
die ("Error:Maximum length of Name exceeded");
}
if(trim($_POST['fnam']) == "")
{
die ("Enter a valid name");
}
if(preg_match('/[^A-Za-z .]/', $_POST['fnam']))
{
die ("Error: Name should be a character value.");
}
can u please explain me how should i use your code ....this is the code i am using for first name
<label>4(a). First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>"><br><br>
then
$fnam=($_POST['fnam']);
if(strlen($fnam)>10 || strlen($mnam)>10 || strlen($lnam)>10)
{
die ("Error:Maximum length of Name exceeded");
}
if(trim($_POST['fnam']) == "")
{
die ("Enter a valid name");
}
if(preg_match('/[^A-Za-z .]/', $_POST['fnam']))
{
die ("Error: Name should be a character value.");
}
Re: Help me code in php: very urgent
om.bitsian wrote:friends i am new in php
can u please explain me how should i use your code ....this is the code i am using for first name
<label>4(a). First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam']; ?>"><br><br>
then
$fnam=($_POST['fnam']);
if(strlen($fnam)>10 || strlen($mnam)>10 || strlen($lnam)>10)
{
die ("Error:Maximum length of Name exceeded");
}
if(trim($_POST['fnam']) == "")
{
die ("Enter a valid name");
}
if(preg_match('/[^A-Za-z .]/', $_POST['fnam']))
{
die ("Error: Name should be a character value.");
}
lol mate
please don't cross-post so many same stuffs! please kindly ask questions in this forum.
-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
Re: Help me code in php: very urgent
sorry for pasting code........thanks SimonMayer header() concepts is working fine