Jump to content

[SOLVED] form handling


bogdaniel

Recommended Posts

hello.. i need a small help from you guys.. and i'm trying to make a function for form validating and i'm stuck on form errors i've got no clue and no ideea how should i do that that part if user is incorect to show me next to that field an error or if password is incorect to show me next to password field an other erorr please can you help me ? thanks alot

Link to comment
https://forums.phpfreaks.com/topic/128088-solved-form-handling/
Share on other sites

The easiest method is to post onto the page with the form.. so on

 

form.php

<?php
if($_POST['submit'] == 'true') {
// Handle form data here, things like is the username the right size, etc. and set an error message
// For example...
$errors = array();
if(empty($_POST['username']) || strlen($_POST['username']) > 9) {
	$errors['username'] = 'Your username is not the right length';
}
}
?>
<form method="POST" action="form.php">
Username: <input type="text" name="username" maxlength="9" /> 
<?php echo (isset($errors['username'])) ? $errors['username'] : '' ?><br />
<input type="submit" name="submit" value="true" />
</form>

 

Of course there are other methods to do this, but this is the most simple.

Link to comment
https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663354
Share on other sites

Seems to me you will need to use javascript or AJAX for thing you are asking for.

 

There are plenty of simple scripts on Google.

 

Try Google for: "javascript form validation"

 

Cheers

 

Yes, if he wants real-time validation of input (every time the user puts in a char it tells him if the value is valid) he should use javascript. I'd recommend LiveValidation... http://www.livevalidation.com/

 

He still will want to use server-side validation though, such as in my example above, since people could very easily disable javascript.

 

http://www.livevalidation.com/

 

To reiterate, javascript validation is convenient, not secure.

Link to comment
https://forums.phpfreaks.com/topic/128088-solved-form-handling/#findComment-663396
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.