Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/197261-input-text/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035448
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/197261-input-text/#findComment-1035459
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.