Jump to content

Need some help with dynamic form


dink87522

Recommended Posts

Okay, so I have a page with a heap of fields and buttons on it (and want to keep it like that really) inside one form.

 

Layout

Box 1 Button 1

Box 2 Button 2

Box 3 Button 3

Box 4 Button 4

etc...

 

Box 1 is called 'amount1$id'

Box 2 is called 'amount.$id' where $id is the $id of the data being displayed etc

 

So a sample form may look like

Box: "amount22" Button: "Pay22"

Box: "amount25" Button: "Pay25"

Box: "amount32" Button: "Pay32"

Box: "amount39" Button: "Pay39"

Box: "amount420" Button: "Pay420"

 

Its working fine up to that point.

 

My problem now is that I can't work out how to get that id number from the form once submitted. If I could get the button name somehow I could do it, although I don't know the button or box names when writing the processing script. I could use a loop and check if button1 to buttonX was posted etc, although if there is a large number of entries in the database, then that starts to become a problem. Thoughts?

Link to comment
Share on other sites

Okay, I don't get it.

 

My form now looks like

<input type='submit' name='Pay[60]' id='Pay[60]' value='Pay' />
<input type='submit' name='Pay[60]' id='Pay[89]' value='Pay' />
<input type='submit' name='Pay[60]' id='Pay[95]' value='Pay' />

etc

 

My processing form part look like:

 

$ID = strip_tags($_POST['Pay']);

$ID = mysql_real_escape_string($ID);

 

$ID is coming through as an array although I can't get/find the array contents (using print_r only gives "Array"). I even tries $ID[0] and $ID[1' etc although had no luck. What am I doing wrong???

Link to comment
Share on other sites

Using strip_tags() on an array produces an error and returns nothing. Are you developing and debugging your code on a system with error_reporting set to E_ALL (or a -1) and display_errors set to ON so that all the php detected errors in your code will be reported and displayed? You will save a TON of time.

Link to comment
Share on other sites

The 'code' you posted in reply #5 works after you remove the error producing strip_tags() from it (also, since $_POST['Pay'] is an array, using mysql_real_escape_string on it produces an error and returns nothing that the suggested php error_reporting/display_errors settings would help you find.)

 

In your last tread, where you were trying to access sequentially numbered form fields, someone suggested displaying the $_POST array so that you can see what you are actually receiving. I recommend you do the same in this thread.

 

You haven't exactly defined what you are trying to do (little or no real code), so it is not exactly possible to help you with it. What you posted in reply #5 produces an array $_POST['Pay'] that contains - Array ( [60] => Pay ) that has a key that you used in the form name and a value 'Pay'.

Link to comment
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.