refiking Posted June 8, 2007 Share Posted June 8, 2007 On the action page, I check certain fields to make sure they are only digits. If not, it returns false. What I'd like to do is show the form again with the responses the user entered, but leaving the incorrect fields blank. Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/ Share on other sites More sharing options...
gazalec Posted June 8, 2007 Share Posted June 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270731 Share on other sites More sharing options...
r-it Posted June 8, 2007 Share Posted June 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270736 Share on other sites More sharing options...
refiking Posted June 8, 2007 Author Share Posted June 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270836 Share on other sites More sharing options...
per1os Posted June 8, 2007 Share Posted June 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270839 Share on other sites More sharing options...
refiking Posted June 8, 2007 Author Share Posted June 8, 2007 Can you give me an example of what it looks like? input value='<? echo (your session id) ?>' Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270841 Share on other sites More sharing options...
per1os Posted June 8, 2007 Share Posted June 8, 2007 // 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. Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270844 Share on other sites More sharing options...
refiking Posted June 8, 2007 Author Share Posted June 8, 2007 Parse error: parse error, unexpected ':' in /home/ctpwebco/public_html/leads/leads.php on line 110 Here is my line 110 Borrower's Last Name: <input type="text" name="name" value="<?php isset($_SESSION['$name']):$_SESSION['$name']:''; ?>" /><br> Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270858 Share on other sites More sharing options...
per1os Posted June 8, 2007 Share Posted June 8, 2007 <?php isset($_SESSION['$name'])?$_SESSION['$name']:''; ?> Replace that, forgot the ? instead of : Quote Link to comment https://forums.phpfreaks.com/topic/54737-solved-php-form-question/#findComment-270862 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.