fantomel Posted June 29, 2009 Share Posted June 29, 2009 hello i'm having some troubles with a form can someone help me ? i want to output some errors in a certain place. but i can't manage do it:( <?php function show_register() { $error_string = ''; echo '<form id="loginform" method="post" action=""> <fieldset> <legend> Register </legend> <p> '. $error_string.' </p> <label for="username"> <input name="username" tabindex="1" id="username" type="text">Username: </label> <label for="password"> <input name="password" tabindex="2" id="password" type="password">Password: </label> <label for="Name"> <input name="name" tabindex="3" id="name" type="text">Name: </label> <label for="Surname"> <input name="surname" tabindex="4" id="surname" type="text">Surname: </label> <label for="address"> <input name="address" tabindex="5" id="address" type="text">Address: </label> <label for="email"> <input name="email" tabindex="6" id="email" type="text">Email: </label> <label for="phone"> <input name="phone" tabindex="7" id="phone" type="text">Phone: </label> <label for="zipcode"> <input name="zipcode" tabindex="8" id="zipcode" type="text">Zip Code: </label> <label for="city"> <input name="city" tabindex="9" id="city" type="text">City: </label> <label for="submit"> <input name="submit" id="submit" tabindex="4" value="Log in" type="submit"> </label> </fieldset> </form>'; } if(isset($_POST['submit'])) { $errors = array(); $valid = 0; if(empty($_POST['username'])) { $valid = 1; $errors['username'] = "Empty Username Field"; } if(count($errors) > 0) { global $error_string; $error_string = implode('</li><li>', $errors); $error_string = " <div class='form_errors'> The following errors were encountered while processing your request: <ul><li>{$error_string}</li></ul> </div> "; show_register($errors); } else { processform(); } } else { show_register(); } function processform() { echo "Registered"; } ?> ok where i have if(count($errors) > 0 .. i would like that output to be inside the form after validation but i`m a little tired and i'm escaping something in the logical part. i would require some assistance. Quote Link to comment Share on other sites More sharing options...
aggrav8d Posted June 29, 2009 Share Posted June 29, 2009 function show_register() { $error_string = ''; echo '< should be function show_register($error_string='') { echo '< Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 Two things for one, inside of the show_register() function you set $error_string to = ''; which is no good, it will always equal nothing. Second you did not build the function to accept variables, so it will not use them. you need to start it like this. <?php function show_register($errors){ if(!isset($errors)){ $error_string=''; } else{ $error_string=$errors; } //etc. ?> Quote Link to comment Share on other sites More sharing options...
fantomel Posted June 29, 2009 Author Share Posted June 29, 2009 thank you very much for you help it gave me an illumination one night with out sleep it's just killing me.. this should be the second night.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.