Welcome Guest, Not a member yet? Register   Sign In
form validation with error message and remain user value in input box...........................
#1

[eluser]ranjitbd[/eluser]
Code:
<html>
<head>
<title><?php echo "Test Form";?></title>
</head>
<body>

<?php echo form_open('form'); ?>
// a simple registration form.....................
<h5>Username</h5>
&lt;?php echo form_error('username'); ?&gt;  // it is for showing error individually ....
&lt;input type="text" name="username" value="&lt;?= set_value('username')?&gt;" size="50" /&gt;
// here set_value to remain the user input value.......

<h5>Password</h5>
&lt;?php echo form_error('password'); ?&gt;
&lt;input type="text" name="password" value="&lt;?= set_value('password')?&gt;" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;?php echo form_error('passconf'); ?&gt;
&lt;input type="text" name="passconf" value="&lt;?= set_value('passconf')?&gt;" size="50" /&gt;

<h5>Email Address</h5>
&lt;?php echo form_error('email'); ?&gt;
&lt;input type="text" name="email" value="&lt;?= set_value('email')?&gt;" size="50" /&gt;

<div><br />&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;?php
$end_tag = '&lt;/body&gt;&lt;/html>';
echo form_close($end_tag);
?&gt;

//// if i use a student info form for editing instead of registration i need to show value from databases. for that i can use value="&lt;? echo $Studentname?&gt;". showing below..

// imagine that it is a student form for showing list of student and edit student

[code]
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo "student form";?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php echo form_open('form'); ?&gt;

<h5>Studentrname</h5>
&lt;?php echo form_error('studentrname'); ?&gt;  // it is for showing error individually ....
&lt;input type="text" name="studentrname" value="&lt;?= $studentrname;?&gt;" size="50" /&gt;

// here i used $studentrname for showing the name from database for editing.
// here how i use the set_value method to remain the username if update fails
// suppose the user click update and change the name..but few input field is blank
// and failed update for form_validation...
// my question is i want to show the user info already given for update..thats why i need set_value function...but how can i use it.

<h5>Address</h5>
&lt;?php echo form_error('address'); ?&gt;
&lt;input type="text" name="address" value="&lt;?= set_value($address)?&gt;" size="50" /&gt;
// &lt;?= set_value($address)?&gt; ............is it correct?

<h5>Class</h5>
&lt;?php echo form_error('class'); ?&gt;
&lt;input type="text" name="class" value="&lt;?= $class ?&gt;" size="50" /&gt;

<h5>Email Address</h5>
&lt;?php echo form_error('email'); ?&gt;
&lt;input type="text" name="email" value="&lt;?= $email?&gt;" size="50" /&gt;

<div><br />&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;?php
$end_tag = '&lt;/body&gt;&lt;/html>';
echo form_close($end_tag);
?&gt;

// all the question is commented by '//' in the coding
// plz help




Theme © iAndrew 2016 - Forum software by © MyBB