Jump to content

Recommended Posts

This can take a while,

The way i done it was on the PHP Checking page make it check each input one at a time such as

if($_POST['username'] == ''){
$error1 = 'You Did Not Enter A Username';
}else{
$error1 = '';
} 

 

And then assign each of these errors to a session as well as all the inputs and then if an error occurs on a certain input then make it blank such as

 

if($error1 != ''){
$username = '';
}

 

Then back on your form page in the input tag have, input value='<? echo (your session id) ?>'

 

I hope you can make sense of that it is quite hard to understand and explain

I'll go 1 ahead of you gazalec and tell him tht whn doing his validation, he should store the errors in an array or something, and then return them to the page, lemme giv u an example

 

if($_POST['username'] == ''){
$errors[] = 'You Did Not Enter A Username<br>';
}
if($_POST['password'] == ''){
$error[] = 'You Did Not Enter A password<br>';
}
if($_POST['fullname'] == ''){
$error1 = 'You Did Not Enter your Full name';
}

then after tht all thts done, you return the array and break it apart and diplay it or something

 

Then back on your form page in the input tag have, input value='<? echo (your session id) ?>'

 

I hope you can make sense of that it is quite hard to understand and explain

 

I got everything else updated, but what is a session id?

 

The session_id is only necessary if you are not using session_cookies, and if you are not and you are worried about SEO I would suggest doing so.

 

www.php.net/session  will help you learn about sessions.

// form.php

<?php
session_start();
?>

<input type="text" name="full_name" value="<?php isset($_SESSION['fullname']):$_SESSION['fullname']:''; ?>" />

 

// process.php

<?php
session_start();

foreach ($_POST as $key => $val) {
    $_SESSION[$key] = $val;
}

$errors = array();
if($_POST['username'] == ''){
   $errors[] = 'You Did Not Enter A Username<br>';
}
if($_POST['password'] == ''){
   $errors[] = 'You Did Not Enter A password<br>';
}
if($_POST['fullname'] == ''){
   $errors[] = 'You Did Not Enter your Full name';
}

if (count($errors) > 0 && $errors[0] != "") {
    include('form.html');
    die();
}else {
// process the data here
}

?>

 

What I am getting at is you do not necessarily need to define the session id, in fact given the code I posted session would be useless too. Do not worry about the echo your session id crap, it is really useless as the best way for sessions is via cookies and even it is not setup with COOKIES and you are using SESSIONS PHP will automatically append the SESSION id to the form. The amazing wonders of PHP.

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.