Jump to content

trouble submitting (preg_match)


cemmetje

Recommended Posts

Hello folks,

 

I am busy with some code that is handled with preg_match. When a certain kind of text is enter and recognized the next box is highlighted for input. Once all input is recognized you are able to press the Send button.

 

All works. Expect for one thing. When the first textbox start with a 2, it is recognized, but it is not coupled to the last textbox. Which holds the form from being submitted.

 

How can i make sure that when a certain textbox input starts with a 2, the preg_match should be ignored?

 

Cheers!

<html>
<head>
<link REL=StyleSheet HREF="css/style.css" TYPE="text/css" MEDIA=screen />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="css/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

<link rel="stylesheet" href="css/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

</head>

<body onload="document.barcodefrm.barcode.focus()">

<div id='wrapper'>

<img class='bird' src='css/bird.png' alt="Logo"  />
<img class='logo' src='css/logo.gif' alt="Logo"  />
<br><H1>
Please book all items you use by scanning the barcodes<br>
and press Send to store when all fields are filled correctly.</H1>


<br>
<div id ='content'>
<div id='contentwrapper'>

<?php
session_start();
if ($_GET['reset']=="true") {
	session_destroy();
	Header("location: scanform.php");
}
include("functions.php");

  function check_form_input($array) {
      if (isset($array['wo']) AND isset($array['user']) AND isset($array['plane']) AND isset($array['qty']) AND isset($array['part']) ) {
          return true;
      } else {
        return false;
      }


  }

        



        if (isset($_POST['barcode'])) {
                echo 'Barcode scanned: ';
                $barcode = $_POST['barcode'];

                if (substr($barcode,0,2)=="RO" or substr($barcode,0,2)=="RD") {
                        echo "Partnumber.";
                        /* hier nog de query bakken voor amos */




                        $_SESSION['form']['part']=getpartnumber($barcode);
                } elseif (preg_match( '/^WO[0-9]{7}(?:-[0-9]{2})?/', $barcode)) {
                        echo "Workorder number.";
                        $_SESSION['form']['wo']=getworkorder($barcode);
                } elseif (preg_match( '/^SG\.[A-Z]{5,6}$/', $barcode)) {
                        echo "Nayak user sign.";
                        $_SESSION['form']['user']=substr($barcode,3,999);
                } elseif (preg_match( '/^AC\.[A-Z]{3,4}$/', $barcode)) {
                        echo "Aircraft.";
                        $_SESSION['form']['plane']=substr($barcode,3,999);
                } elseif (preg_match( '/^[0-9]{1,2}$/', $barcode)) {
                        echo "Quantity.";
                        $_SESSION['form']['qty']=$barcode;
                } else {
                        echo "This is not a valid barcode.";
                }

        }

   

?>

<form name="barcodefrm" id="barcodefrm" method="post" action="scanform.php?reset=false">

<div class="form-row"><span class="label">Scan barcode:</span> <input type="text" name="barcode" id="barcode"></div>
<div class="form-row"><span class="label"> </span> <!--<input type="submit" class='send' value='Reset'>--> </div>
</form>




  
  <form id="form1" method="post" action="scanform.php">



<div class="form-row"><span class="label">Workorder: </span><input type="text" name="wo" value="<?= $_SESSION['form']['wo']; ?>"></div>
<div class="form-row"><span class="label">User sign: </span><input type="text" name="user" value="<?= $_SESSION['form']['user']; ?>"></div>
<div class="form-row"><span class="label">Part: </span><input type="text" name="part" value="<?= $_SESSION['form']['part']; ?>"></div>
<div class="form-row"><span class="label">Location: </span><input type="text" name="location" value="<?= $_SESSION['form']['location']; ?>"></div> 
<div class="form-row"><span class="label">Quantity: </span><input type="text" name="qty" value="<?= $_SESSION['form']['qty']; ?>"></div> 
<div class="form-row"><span class="label">Aircraft: </span><input type="text" name="plane" value="<?= $_SESSION['form']['plane']; ?>"></div> 
<div class="form-row"><input class="submit" type="submit" name="submit" value="Send to store" class='sendbutton' 
<?php
if (!check_form_input($_SESSION['form'])) { echo "disabled"; }

?>></div>

</form>

<input type="submit" class='send' value='Reset values' onclick="location.href = '?reset=true'">

<pre>
<?php
//print_r($_SESSION['form']);
?>
</pre>
</div>
</div>

</div>
<script type="text/javascript">

$("#form1").bind("submit", function() {



$.fancybox.showActivity();
  
$.ajax({
	type		: "POST",
	cache		: false,
	url			: "saveform.php",
	data		: $(this).serializeArray(),

	success		: function(data) {
						$.fancybox(data,
						{
							'onClosed'				: function() {
														location.href='?reset=<?= ($debug ? "false" : "true"); ?>';
													}
						});
				}
});

//location.href='?reset.true';

return false;

});
</script>
</body>
</html>



 

[attachment deleted by admin]

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.