m4ttphpnewb Posted February 13, 2008 Share Posted February 13, 2008 Can anyone help me with a code to remove % and ? characters from a text box when a card is swiped through the reader. For example "%ABC?" needs to be changed to "ABC" Thanks! Quote Link to comment Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 str_replace('%', '') str_replace('?', '') Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 13, 2008 Share Posted February 13, 2008 If you're wanting them to be removed from the text box rather than PHP replacing them, you're going to have to look at Javascript. I believe most card readers try to press enter or submit once the card has been scanned, so you could look at some Javascript events for that Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 13, 2008 Author Share Posted February 13, 2008 Ok thank you I will look around. Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 ok I have tried a few things with the str_replace() function and can't seem to get it to work with my text box. this is my last thing to fix on my page and it is driving me nuts.(I had to change script to scrip t to post it in the forum) $fullname = str_replace('%','',$fullname) ; $fullname = str_replace('?','',$fullname); echo " <input type='text' name='left_fullname' id='textbox1' > <scrip t>document.getElementById('textbox1').focus()</scrip t>\n"; if (!$fullname) { echo " <td align=left class=right_main scope=col>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo "<br />\n"; echo "You have not chosen a username. Please try again\n"; include 'footer.php'; exit; } @$fullname = addslashes($fullname); Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 What does the card reader output to the text box currently? Is it always characters only or are there numbers aswell? Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 it outputs %xyz? to the text box Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 I have been testing it with a card encoded as %DEMO1000? I need it to read in the text box as DEMO1000 so the database recognizes it Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 Are you bothered about the values within the text box? Because once you submit the form we can let PHP take care of the odd symbols, or would you prefer to use Javascript to get rid of the % and ? as soon as it's swiped. Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 i am not bothered by the values in the box, i just need them gone to submit Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 Ok then, go to the part of your page where you process the submission. Then you can remove the % and ? by doing this: $fullname=$_POST['left_fullname']; $fullname= str_replace('%','',$fullname) ; $fullname = str_replace('?','',$fullname); That'll remove all % and ? within the textbox after it's submitted, and then you can insert/update your database Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 no go, maybe because of this at the beginning of my page? if ($request == 'POST'){ @$fullname = stripslashes($_POST['left_fullname'])}; Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 got it! (with your help !!) if ($request == 'POST'){ @$fullname = stripslashes($_POST['left_fullname']); @$fullname= str_replace('%','',$fullname) ; @$fullname = str_replace('?','',$fullname);} Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 any idea on how to make it not auto submit when swiped? for now i think I will just move it beneath the buttons and change the buttons so they don't submit then have the whole thing submit with the card swipe. Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 It's just what card readers usually do I'm afraid. They automate Enter I think once they've finished swiping, which is what will be submitting the form (probably the first submit button too). There may be a setting that you can change on the card reader though - so that it doesn't auto submit. Quote Link to comment Share on other sites More sharing options...
m4ttphpnewb Posted February 14, 2008 Author Share Posted February 14, 2008 hahah I will beat the card reader! (against the wall till it stops auto entering) nope I will work on a work around and post back when I have out smarted the little piece of hardware, thanks for helping me out so much Im beginning to feel my way around the code much better Quote Link to comment 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.