Jump to content

Recommended Posts

Hi,

 

I'll try and explain this best I can. I have a result set being pulled from the database from a products table. Each product will have a textfield associated with it so the user can enter in the quantity they would like to order. So each textfield is named after the id of the product, that seems to make sense.

 

What I dont understand is, how to get the values of the textfields that have data entered in them when the form is submitted. eg.

 

prod1 - quantity: (0)

prod2 - quantity: (15)

prod3 - quantity: (2)

prod4 - quantity: (0)

prod5 - quantity: (1)

 

So this result pulled 5 results from the database, each with its respective textfield. When the form is submitted how to I know that prod2, prod3 and prod5 have data in them?

Link to comment
https://forums.phpfreaks.com/topic/117317-solved-dynamic-textfields/
Share on other sites

I think there might be a problem with how I use that and the way I check for submission. It seems to print..

 

process - quantity: (execute)

 

Do I need to link the textfield's with the $v array value some how? .. if that makes any sense!

 

<?php

        //Check to see if form has been submited

$process = $_POST['process'];
if($process != "execute")
{
	//Do noting...
}
else
{

foreach ($_POST as $k => $v) {
        if ($v != '' && $k != 'submit') {
        echo "$k - quantity: ($v)<br />";
  }
}



}


?>

 



         ...........

        <input type="hidden" name="process" value="execute" />
<button type="submit">Submit</button>  

I've changed it to that alright but still cant get it to work. I understand what the code is trying to do alright. I added a print "Hello World" just to make sure its going in after submission and it is, but the echo quantity will not print.

 

<?php

  if (isset($_POST['submit'])) {

  echo "Hello World";

    foreach ($_POST as $k => $v) {
      if ($v != '' && $k != 'submit') {
        echo "$k - quantity: ($v)<br />";
      }
    }
  }

?>

This test....

 

<html>
<head>
  <title>test</title>
</head>
<body>
<?php

  if (isset($_POST['submit'])) {

    foreach ($_POST as $k => $v) {
      if ($v != '' && $k != 'submit') {
        echo "$k - quantity: ($v)<br />";
      }   
    }
  }

?>
  <form method="post">
   <input type="text" name="foo"><br />
   <input type="text" name="bar"><br />
   <input type="text" name="bob"><br />
   <input type="submit" name="submit"><br />
  </form>
</body>
</html>

 

Works fine on my server.

I've modified it slightly to this and it seems to work for me now...

 

<?php

  if (isset($_POST['submit'])) {
  
foreach ($_POST['val'] as $k => $v)
{
      if ($v != '' && $k != 'submit') {
        echo "$k - quantity: ($v)<br />"; }
  
  }
}

?>


......

<input type='text' name='val[".$row[0]."]' style='width:35px;' />

 

Thanks for your help!

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.