html5 - how initiate a validation form using php -


i trying following validation on registration page;

at beginning of page have,

<?php if(!isset($_post['sumbit']) && (!validatename($_post['phonenumber'])) { here html show errors if form submitted errors <form method= "post" action="<?php echo htmlspecialchars($_server['php_self']);?>"> <div>phone number</div> <input type="text" name="phonenumber" size="20" placeholder="phone" value="<?php echo htmlspecialchars($_post['phonenumber']); ?>" required> <input type="submit" name="submit" value="next"> </form> 

but getting "notice: undefined index: phonenumber in ...." before submit page

i have validationname function in separated file call here getting error

any help??

you have validate variable set:

if(isset($_post['var'])) 

or (for checking if not empty):

if(!empty($_post['var'])) 

but can ignore notices, not best solution, not shown on productive environments. furthermore, can leave out this:

action="<?php echo htmlspecialchars($_server['php_self']);?>" 

for error (variable not set), try displaying posted things:

var_dump($_post); 

edit: there logical mistake:

if(!isset($_post['sumbit']) && (!validatename($_post['phonenumber'])) { 

should this, display in case of error:

if(isset($_post['submit']) && !validatename($_post['phonenumber'])) { 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -