Jump to content

form trouble


fantomel

Recommended Posts

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.

Link to comment
Share on other sites

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.
?>

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.