Jump to content

Error check form going to another page


richrock

Recommended Posts

Well, it's that time again.  Yes.  I am stuck.

 

Had a mate of mine show me how to error check a form once submitted.  The code he showed me has:

 

// Add User Details
function checkFormValidation() {

	// Generate the result errors if anything missed.		
	if (!$firstname) {$errmsg=$errmsg. "- First Name is a required field.<br />"; $continue=false;}
	if (!$lastnamename) {$errmsg=$errmsg. "- Last Name is a required field.<br />"; $continue=false;}
	if (!$telephone) {$errmsg=$errmsg. "- Telephone Number is a required field.<br />"; $continue=false;}
	if (!$username) {$errmsg=$errmsg. "- Username is a required field.<br />"; $continue=false;}
	if (!$email) {$errmsg=$errmsg. "- Email Address is a required field.<br />"; $continue=false;}

	//Check for dull people entering data...
	if (!$continue) {

//Error in the input of the form, person entering data is a n00b

		echo "<strong>Error in form, incorrect data</strong><br />";
		echo $errmsg."<br />";
		die();

	}	

}

 

Now I'm posting the form to another page (it writes the user details to the DB, loads the page, then displays the details along with a further form...

 

But if something is missing, I'm now on the second page (using <form action="second_page.php"...) and can't get back to the original form without losing the entered form information.

 

Now my thinking is that this will have to be processed by a javascript function to check the form, and if ok, carry on with the $_POST onto the next page.  Is this right?

 

Something along the lines of function checkForm (

  make sure the form.is.complete;

)

 

I should be able to cope with that.  But is there a way to keep it within PHP and push my knowledge further?

 

Rich

 

Link to comment
https://forums.phpfreaks.com/topic/125814-error-check-form-going-to-another-page/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.