0

I'm looking for an answer or perhabes an idea to solve this problem ..

i have a form to be filled and the code checks after submmiting if there's empty textbox's it'll print an error message, however when it returns to the form page all previous user entry will be gone and then he has to fill them all again .. which i believ is annoying !

how can i reserve the entry .. please i want i short solution bcause i have so many forms with so many fildes .

You can check my work so far :

this is to check in the formExcution.php

 if(    $jobn==""||$jobc==""||$salaryn==""||$salaryc==""||$transportn||$transportc==""||$residencen     ==""||$residencec==""||$benifitn==""||$benifitc==""||$packagen=="")
  {
 header("location: editsalaryform.php?msg=empty");
    exit();
        }

and here in the form page where the message will shown:

       <?php 
        if(isset($_GET['msg'])){
       print "<h4 style='color:#700000;'> you have to fill all the fildes   </h4>";}
       ?>

Thank you ,

proG
  • 111
  • 1
  • 5
  • 12

6 Answers6

2

CodeIgniter PHP Framework has some support for this check the link below


http://codeigniter.com/user_guide/libraries/form_validation.html

Also check this tutorial it helps a lot

http://gazpo.com/2011/07/codeigniter-jquery-form-validation/

Dinesh P.R.
  • 6,936
  • 6
  • 35
  • 44
0

First of all , using JS you can check whether a certain field is filled or not. Furthermore , if you want to validate the content in the fields under another paramenters, in case the user have to refill some fileds, you always post the filled form and let the user edit it , for example:

if(isValid(....)) {
 .....
} else { 
 echo "<input type="text" name="123" value='{$notValidContent}'" ; 
}

Assume that $notValidContent is the content of the email field , which you found out the user did not fill propely. Then the codeline above echoes the information the user filled in the field. You can employ this method in order to post any data the user filled in the form .

0

you can use javascript validation so you won't need to do a full page refresh when the user submits your form. But its wise to do server-side validation as well so you might as well use php sessions to store the value of form fields:

$_SESSION['jobn'] = $jobn

and just echo out the session on the redirect page:

<input type="text" name="jobn" value="<?php echo $_SESSION['jobn']; ?>"/>

Just set:

session.auto_start = 1

In php.ini file so you won't need to do:

session_start()

On every page where you need to use sessions.

Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139
0

you can solve it by either storing all the values to session or just echo $_POST['name'] to each inputs

Max
  • 117
  • 4
  • 18
0

For example you have a form like this:

<form method="post" action="index.php">
    <input name="username" placeholder="username"/>
    <input type="submit" value="Kill user"/>
</form>

and you want to save the username if it doesn't exist. So, in the same page you change and add this:

<?php
    $username = "";
    if (!empty($_GET["u"]))
    {
        $username = $_GET["u"];
    }
?>
<form method="post" action="index.php">
    <input name="username" placeholder="username" value="<?echo "$username"?>"/>
    <input type="submit" value="Kill user"/>
</form>

and in the index.php, you retrieve the username and send it to the form page when it doesn't pass in this format.

So you add something like this in the index.php:

<?
    if (!empty($_POST["username"] && !empty(Protected[$_POST["username"]]))
    {
        header("Location: http://sitename.com/kill.php?x=2&u=".$_POST["username"])
    }
    else
    {
        // Kill the user
    }
?>

In the above code, I also tell the page to say error 2 (the user is protected etc. etc.)

Check out an example of this here.

j0k
  • 22,600
  • 28
  • 79
  • 90
qaisjp
  • 722
  • 8
  • 31
0

THANK YOU ALL .. it works fine now .. ! I only used this from the jQuery library ..!!

         <script>
         $(document).ready(function(){
          $("#form1").validate();
           });
           </script>

Really big thanks to YOU all !

proG
  • 111
  • 1
  • 5
  • 12