Ch3vr0n Posted March 8, 2009 Share Posted March 8, 2009 I'm in the process of creating a form but I'm running into a problem. I'm not that experienced with php/sql so I'll define what i need here. There is a field called "klantnummer" that needs to be in a fixed format. The format will be as followed "xxxx-yyy". Where xxxx will be the year (eg 2008, 2009, ....), - will be the mandatory divider, and yyy will be another number but not fixed in length. A valid number would be like 2008-001 or 2009-1 or 2009-03. The fixed part is "xxxx-", that will always stay like that. To see if a "klantnummer" is valid, it needs to verify if the "klantnummer" exists in the database "klanten". I know there is a function or somethin called mysql_fetch_object but i don't really know how to use it or if there is a simpler way. The page that has the form coded is separate. eg page : index.php has the form created in HTML > form action = stap2.php what i have so far is this. <?php session_start(); $naam=$_POST['naam']; $voornaam=$_POST['voornaam']; $klantnummer=$_POST['klantnummer']; $afdeling=$_POST['afdeling']; $bericht=$_POST['bericht']; $onderwerp=$_POST['onderwerp']; $secure = trim(strip_tags($_POST['secure']));// leave case as entered $match = $_SESSION['captcha']; // the code on the image if (($secure!=$match) && ($secure!="")) { echo " Security code ongeldig.<br/> Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw. "; } if ($secure=="") echo "Security code niet ingevuld.<br/> Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw. "; elseif(($secure==$match) && ($secure!="")) { if (($naam=="") || ($voornaam=="") || ($klantnummer=="") || ($afdeling=="") || ($onderwerp=="") || ($bericht=="")) { echo "1 of meerdere velden niet ingevuld.<br/> Ga <a href=\"javascript:history.go(-1)\">Terug</a> en controleer de velden."; } else echo $naam."<br/>".$voornaam."<br/>".$klantnummer."<br/>".$afdeling."<br/>".$onderwerp."<br/>".$bericht; // temporary code to see if data is transmitted } ?> Can you guys help me ? Link to comment https://forums.phpfreaks.com/topic/148487-fixed-text-field-format/ Share on other sites More sharing options...
Ch3vr0n Posted March 22, 2009 Author Share Posted March 22, 2009 bumpie. Anyone. The code has chenged in the mean time. <?php session_start(); $naam=$_POST['naam']; $voornaam=$_POST['voornaam']; $email=$_POST['email']; $klantnummer=$_POST['klantnummer']; $afdeling=$_POST['afdeling']; $onderwerp=$_POST['onderwerp']; $bericht=$_POST['bericht']; $secure = trim(strip_tags($_POST['secure']));// leave case as entered $match = $_SESSION['captcha']; // the code on the image if (($secure!=$match) && ($secure!="")) { echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Security code ongeldig.<br/>Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw. "; } if ($secure=="") { echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Security code niet ingevuld.<br/> Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw."; } elseif(($secure==$match) && ($secure!="")) { if (($naam=="") || ($voornaam=="") || ($email=="") || ($klantnummer=="") || ($afdeling=='kies') || ($onderwerp=="") || ($bericht=="")) { echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />1 of meerdere velden niet ingevuld.<br/>Ga <a href=\"index.php\">Terug</a> en probeer opnieuw."; } elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Ongeldig e-mail adres ingevuld.<br/>Ga <a href=\"index.php\">Terug</a> en probeer opnieuw."; } /* klantnummer field formatcheck goes here. Based on klantnummer, extra info will be retrieved from database */ else { ?> <html> <head> <link rel="stylesheet" href="../../../../templates/techline_de_template-j15-001/style2.css" /> </head> <body> <form action="send.php" method="post"> <table> <tr> <th colspan="2">Gelieve onderstaande gegevens te controleren.</th> </tr> <tr> <td>Naam: <?php echo $naam ?><input type="hidden" name="naam" value="<? echo $naam ?>" /></td> <td>Voornaam: <? echo $voornaam ?><input type="hidden" name="voornaam" value="<? echo $voornaam; ?>"/></td> </tr> <tr> <td colspan="2">E-Mail: <?php echo $email ?><input type="hidden" name="email" value="<? echo $email ?>"/></td> </tr> <tr> <td>Klantnummer: <? echo $klantnummer ?><input type="hidden" name="klantnummer" value="<? echo $klantnummer ?>"/></td> <td>Bestemd voor: <? echo $afdeling ?><input type="hidden" name="afdeling" value="<? echo $afdeling ?>" /></td> </tr> <tr> <td align="center" colspan="2">Onderwerp: <? echo $onderwerp ?><input type="hidden" name="onderwerp" value="<? echo $onderwerp ?>"/></td> </tr> <tr> <td align="center" colspan="2">Uw bericht<br /><? echo $bericht ?><br /><input type="hidden" name="bericht" value="<? echo $bericht ?>" /></td> </tr> <tr> <td colspan="2" align="center">Is dit correct ? Zoja druk op versturen. Indien niet druk op herbeginnen.</td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Versturen" /><input type="reset" value="Herbeginnen" onClick="window.location.href=index.php"></td> </tr> </table> </form> </body> </html> <? } } ?> Link to comment https://forums.phpfreaks.com/topic/148487-fixed-text-field-format/#findComment-790933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.