conditional posting of a record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharmilah
    New Member
    • Jun 2007
    • 20

    conditional posting of a record

    Hi all

    I would be grateful if you could help me in the following issue. I have a form on which I can recall records and modify them. On clicking on the push button 'post', the modified record is updated and a page called guarantee.php is called. But now I want to add some validation so that if there's a mistake in an input field e.g. 'tan' the message 'invalid input' is displayed and instead of calling the program guarantee.php, I am allowed to correct the mistake and post again. If all mistakes are corrected, on clicking post I should go back to guarantee.php but if not the error message should be displayed and I should be allowed to correct. Below are some codes which I have used to return to guarantee.php program after posting. It includes some functions, the description of which I have given in comment form.I have to modify these codes to allow me to correct the mistake and post again. Please help.


    [PHP]<? function editrec($recid)
    {
    $res = sql_select(); // a function that selects the record to be edited
    $count = sql_getrecordco unt(); // a function that gets the numbver of records in the table
    mysql_data_seek ($res, $recid);
    $row = mysql_fetch_ass oc($res);
    showrecnav("edi t", $recid, $count); //a function creating the navigation tools depending on the no of records
    ?>
    <br>
    <form action="guarant ee.php" method="post" name="frmcampai gn">
    <input type="hidden" name="sql" value="update"> //the value "update" of sql is passed to a function to enable update of a record
    <input type="hidden" name="xBkg_Seri alNo" value="<? echo $row["Bkg_Serial No"] ?>">
    <? showroweditor($ row) ?> // displays the fields to be edited
    <p><input type="submit" name="action" value="Post"></p>
    </form>
    <?
    mysql_free_resu lt($res);
    } ?>[/PHP]

    Thanks
  • luke14free
    New Member
    • Apr 2007
    • 79

    #2
    Hi,
    If I have understand what you need you could use another way.
    You can use Spry Ajax(opensurce from adobe labs) and you can inset forms that doesn't allow you to continue(to your 2nd page in php) unless the value respects some standard(that you can edit such as int value, minimal/maximal long and so on...). All in jscript.
    Hope to have been useful

    Comment

    • sharmilah
      New Member
      • Jun 2007
      • 20

      #3
      Sorry but i am a newbie and don't know javascript. Is there no other way.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, sharmilah.

        Is the PHP code on the same page as the form's HTML?

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          When you submit the form, your code should check all fields for validity before any submission is complete.

          Example:

          [code=php]if(!empty($_POS T)) // A form has been submitted
          {
          if(!isset($_POS T['name'], $_POST['email'], $_POST['password']))
          {
          // Create an error message displaying that the form
          // is incomplete
          }
          else if(strlen($_POS T['name']) < 8)
          {
          // Create error message displaying that the name is too short
          }
          else if(!preg_match(/* email regex */, $_POST['email']))
          {
          // Create error message regarding invalid email address
          }
          else
          {
          // Submit the data
          }
          }[/code]

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Have your guarantee page perform the validation, and redisplay the form if the data is bad. Then the page can post to itself and you don't have to worry about automating posts between pages.

            Comment

            Working...