Jump to content

form input during processing


hakimserwa

Recommended Posts

hello to all of you again. i am working on a registration form of about 15 fillable fields, i have set some validation rules to this form but what i want is if one of the rule is not met along the way, lets say the seventh field but all the 1 to 6 and 8 to 15 are were correct, the form on submision must not cancel the initial correct values. it must echo a message at the top but his field values will still exist just what will be needed is him to correct the wrong field and submit again.

Link to comment
Share on other sites

You'll need to set the inputs values to the post/get data, so they get filled automatically on submit. Supposing you're sending the form via post:

 

<input type="text" name="full_name" value="<?php echo $_POST['full_name']; ?>">
<input type="text" name="email" value="<?php echo $_POST['email']; ?>">

Link to comment
Share on other sites

it seems no one is willing to help on this but this was my novice way of solving it and i thought some other mates may find it usefull atleast for the start.

 

if you know how to echo error messages from your process.php or even if you have done self form submission, then you can also use php to archieve form data rataition on submit if the validation was failed.

 

you make your form,

it posts data to your process file in this case its self submission,

then you validate to see if some criterias are met before inserting that data to your table.

then you echo an error messege back to the form in validation was failed.

 

the same way you echo errors is the same way i echoed the form data back to the form using a temporary valuable $field1 and 2 and 3 and so on.

then i globalised the field valuables and places them in the form as values.

 

so every time i have an error trigered on my form page, the temporary field valuable is also trigered and desplayed in the value of the input field on my html form.

 

example

 

<?php
$first_name = $_POST['First_Name'];
$last_name = $_POST['Last_Name'];
$age = $_POST['Age'];
$contact_number = $_POST['Contact_Number'];
$email_address = $_POST['Email_Address'];
$country = $_POST['Country'];

if(isset($_POST['send_info'])){	
if(!trim($first_name)){
	$messege=" Please Provide Your First Name!";
}elseif (is_numeric($first_name)){
	$messege = "Names Must be alphabets only!";
}elseif(preg_match("([0-9])", $first_name) ){
	$messege = "No Numbers Are allowed in Name Fielsds";


}elseif(!trim($last_name)){
	$messege="Sorry  Please Provide Your Last Name!";
	$field1= $first_name;
}elseif (is_numeric($last_name)){
	$messege = "Names Must be alphabets only!";
	$field1= $first_name;
}elseif(preg_match("([0-9])", $last_name) ){
	$messege = "No Numbers Are allowed in Name Fielsds";
	$field1= $first_name;

}elseif(!trim($contact_number)){
	$messege="Sorry Please Provide Your Contact Number!";
	$field1= $first_name;
	$field2= $last_name;
	$field3= $age;
}elseif(preg_match("([a-z][A-Z])", $contact_number) ){
	$messege = "No Alphabates Are Allowed in Contact Fielsds";
	$field1= $first_name;
	$field2= $last_name;
	$field3= $age;

}elseif(empty($email_address)){
	$messege="Sorry  Please Provide Your Email Address!";
	$field1= $first_name;
	$field2= $last_name;
	$field3= $age;
	$field4= $contact_number;
}elseif(empty($country)){
	$messege="Sorry  Please Provide Your Country!";
	$field1= $first_name;
	$field2= $last_name;
	$field3= $age;
	$field4= $contact_number;
	$field5= $email_address;
}elseif(empty($problem)){
	$messege="Sorry Please Explain Your Problem!";
	$field1= $first_name;
	$field2= $last_name;
	$field3= $age;
	$field4= $contact_number;
	$field5= $email_address;
	$field6= $country;
}elseif($messege==false){

	$date = date("d/m/y");
	$sql = mysql_query("INSERT INTO clients (`id`, `Client Id`, `First Name`, `Last Name`, `Age`, `Contact Number`, `Email Address`, `Problem`,  		`Country`,`Consultation Fees`, `Date Joined`, `Status`)
	VALUES
    	('','','$first_name','$last_name','$age','$contact_number','$email_address','$problem','$country','$consultation_fees', '$date',
  	'New')")or die('Error: ' . mysql_error());

$messege=" form subbmited sucessfully 1 record added!";
}else{
echo $messege;

}

}
?>

 

 

Link to comment
Share on other sites

You'll need to set the inputs values to the post/get data, so they get filled automatically on submit. Supposing you're sending the form via post:

 

<input type="text" name="full_name" value="<?php echo $_POST['full_name']; ?>">
<input type="text" name="email" value="<?php echo $_POST['email']; ?>">

 

SORRY I WROTE THIS BEFORE YOU REPLIED

Link to comment
Share on other sites

You would use an array to hold the error messages, with the array index name relating it to the form field (if you want to output the error message next to the corresponding form field), so that you can validate and output messages for all the fields at one time, rather than outputting the first validation error, resubmitting the form, outputting the next validation error....

Link to comment
Share on other sites

it seems like a great idea to learn can you please show me an example. but in the previous post what i was trying to archieve was form fields to retain the filled in data when submted but failed to pass validation.

 

I would appreciate any better idea than myn as i am still a novis i like learning

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.