dardub Posted April 1, 2010 Share Posted April 1, 2010 This should be an easy question, I just can't figure it out. If I have a text input such as: <?php echo " Qty 1: <input type='text' size='2' name='qty'></input>"; ?> and I enter in a number in the field, the value doesn't post to to $_POST['qty']. If I do: <?php echo " Qty 1: <input type='text' size='2' name='qty' value='3'></input>"; ?> the number 3 posts if i just simply do <input type="text" size="2" name="qty"></input> in plain html it works fine, whatever i type in posts to $_POST['qty'] what am I missing? how should i format this? I'm trying to put the form fields into a string variable, that's why I am doing it this way, if that makes sense? Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/ Share on other sites More sharing options...
andrewgauger Posted April 1, 2010 Share Posted April 1, 2010 That is a strange browser behavior, but try: <?php echo " Qty 1: <input type=\"text\" size=\"2\" name=\"qty\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035393 Share on other sites More sharing options...
dardub Posted April 1, 2010 Author Share Posted April 1, 2010 Yea thanks, I had tried that one already too. Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035395 Share on other sites More sharing options...
dardub Posted April 1, 2010 Author Share Posted April 1, 2010 Well if nothing seems wrong with that. I must be doing something wrong elsewhere. I just wasn't sure if I as formatting that wrong. Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035399 Share on other sites More sharing options...
andrewgauger Posted April 1, 2010 Share Posted April 1, 2010 You should make sure your submit butt on is inside the form closing element... not sure why you would get false positives. Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035403 Share on other sites More sharing options...
lefthand Posted April 1, 2010 Share Posted April 1, 2010 How are you checking if you got the correct value (i.e. 3) ? Are you echoing the value or are you looking for an integer? Possibly casting it as an integer? Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035415 Share on other sites More sharing options...
dardub Posted April 1, 2010 Author Share Posted April 1, 2010 just to check i used echo $_POST['qty'] and also tried print_r ($_POST) when I print the array, i get back ['qty'] => with no value i'm going through my code right now and cleaning it up, it's probably some dumb thing i left behind Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035433 Share on other sites More sharing options...
dardub Posted April 1, 2010 Author Share Posted April 1, 2010 Sorry... I had several input boxes with the same name. Therefore it was only grabbing values from the last field named qty. I wasn't thinking about how forms work correctly. What I want is to have only one qty field submitted when I press the submit button next to it. I'm guessing I'll have to use javascript for that? Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035448 Share on other sites More sharing options...
ialsoagree Posted April 1, 2010 Share Posted April 1, 2010 It would probably be better to use different form tags if you want to submit different forums depending on what button is hit (in other words, separate the fields and submit buttons into 2 different form tags). Just as a quick aside though, since it seems to be my favorite thing to point out: using double quotes around a string that doesn't contain text is a waste (albeit a very small amount) of processing power. You're telling PHP to check for PHP variables in the string, but there's no PHP variables there so it's just wasting time. You should instead use single quotes. But in this specific case, the difference in time saved wouldn't even be noticeable. It's more of a "good practice" note, especially if you build highly used or very demanding PHP pages. Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035459 Share on other sites More sharing options...
dardub Posted April 1, 2010 Author Share Posted April 1, 2010 Thanks for the tip, that's good to know. The couple basic php books I've read; I don't remember the mention of that difference between double and single quotes. Is it okay to put double quotes inside of single quotes since it's just a string? Quote Link to comment https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035488 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.