Trying to POST data from a "repeating" form field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Trying to POST data from a "repeating" form field

Post by steedvlx »

Could someone give a an idea why this form doesn't POST the variable prod_id_index properly?

<form name="form1" method="post" action="j_cart/j_confirm_add.php">
<input name="hiddenField" type="hidden" value="<?php echo $row_rs_kb_prod['prod_id_index']; ?>">
<a href="javascript:;" onclick="formButtonFever('form1','submit')"><img src="../images/e_add_to_kart.gif" width="105" height="48" border="0"></a>

Some background on this... I've intended for the button to appear on every row in a DO WHILE search results situation.

I don't know how it is done, so I keep reading things and getting ideas to try. This one makes the most sense, but doesn't pass anything to the receiving page. The variable prod_id_index is contained in the hidden field that the button submits, and is different for each displayed row.

Any insight appreciated.

------------------------
SteedVLX
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

This would give you the variable $_POST['hiddenField'];

Maybe what you're after is:

Code: Select all

<input name="prod_index_id" type="hidden" value="<?php echo $row_rs_kb_prod&#1111;'prod_id_index']; ?>">
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Post by steedvlx »

Thanks for the tip, however something else is amiss. This HTML/PHP code....

Code: Select all

<form name="<?php echo $row_rs_kb_prod&#1111;'prod_kb_part_num'];?>" method="post" action="j_cart/j_confirm_add.php">
        <input name="prod_number" type="hidden" id="prod_number" value="<?php echo $row_rs_kb_prod&#1111;'prod_kb_part_num']; ?>">
        <a href="javascript:;" onclick="formButtonFever('<?php echo $row_rs_kb_prod&#1111;'prod_kb_part_num'];?>','submit')"><img src="../images/j_add_to_kart.gif" width="105" height="48" border="0"></a> 
      </form>
Now outputs this HTML source code for the displayed page...

Code: Select all

<form name="101-111-1237" method="post" action="j_cart/j_confirm_add.php">
        <input name="prod_number" type="hidden" id="prod_number" value="101-111-1237">
        <a href="javascript:;" onclick="formButtonFever('101-111-1237','submit')"><img src="../images/j_add_to_kart.gif" width="105" height="48" border="0"></a> 
      </form>
As you can see, I have rigged it where each data row has a form with a unique name. Now, that name is the part number from the data row. The form name, and all the form values are filled dynamically now. Everything on the catalog view page displays fine. But, alas, I cannot actually get the ACTION page to come up when I click on the add_to_kart (submit) button.

Please help, I'm Lost lost lost.

-----------------------
SteedVLX
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

I think that you must start the form name with an a-z or underscore, try just using the id and have a name like 'item_523'.
corlando
Forum Newbie
Posts: 21
Joined: Sun Jun 15, 2003 10:07 pm

Post by corlando »

just a thought...why not use this.form?

Code: Select all

onclick="formButtonFever(this.form,'submit')
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Post by steedvlx »

releasedj,

Well, I tried that too. Now the resulting HTML is...

Code: Select all

<form action="j_cart/j_confirm_add.php" method="post" name="part101-111-1237">
        <input name="prod_number" type="hidden" id="prod_number" value="101-111-1237">
        <a href="javascript:;" onclick="formButtonFever('101-111-1237','submit')"><img src="../images/j_add_to_kart.gif" width="105" height="48" border="0"></a> 
      </form>
it passes diagnostics, but still no resulting page...


corlando,

I've never seen that before. If you mean literally putting "this.form" in the form name area, then I'll try it and see what happens.

Thanks for the 'eyes'

------------------------
SteedVLX
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

I'll try and give you a better idea into a way of doing this.
It's really quite simple when you get the hang of it:

Before you do the loop, output a form at the top of the page, with the javascript used to submit the form:

Code: Select all

&lt;form action="j_cart/j_confirm_add.php" method="post" name="part_form"&gt;
        &lt;input type="hidden" name="prod_number" value=""&gt;
&lt;/form&gt;

&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
    function formButtonFever (partno)
    &#123;
        var f = document.part_form;
        f.prod_number.value = partno;
        f.submit();
    &#125;
--&gt;
&lt;/script&gt;
then in your loop, do this:

Code: Select all

<a href="javascript:;" onclick="formButtonFever('<?php echo $row_rs_kb_prod['prod_kb_part_num']; ?>')"><img src="../images/j_add_to_kart.gif" width="105" height="48" border="0"></a>
That should do it, or should be pretty close anyway.

Kelvin
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Post by steedvlx »

releasedj,

That looks pretty interesting. I've never studied javascript and have always used packaged stuff. I'll try it first thing tomorrow and see if I can get that to work.

I have found that formbuttonfever is the problem... I've never had a problem with that script, but it is somehow broken by something in the code.

I ripped it out and used the generic (read:hideous) button calls and guess what. The rest of the code works.

Code: Select all

<form action="<?php echo "j_cart/j_confirm_add.php";?>" method="post" name="<?php echo "part" . $row_rs_kb_prod&#1111;'prod_kb_part_num'];?>">
              <input name="prod_number" type="hidden" id="prod_number" value="<?php echo $row_rs_kb_prod&#1111;'prod_kb_part_num'];?>">
              <input type="submit" name="Submit" value="Add to Cart">
            </form>
I never suspected the formbuttonfever script because every button I have on my site thus far uses this script and works great.

Thank you for taking the time to show me the java. I appreciate it and i'll try to understand and implement. If I can't my entire theme is going to be destroyed by those ugly default buttons.

If you or anybody else knows of a good way to use any image I want as a button, I would be grateful to learn that as well.

Well it's 2;00am in my part of Asia...Good nite all!

---------------------
SteedVLX
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

One thing that might help.. When yo renamed the form, you didn't change the call to formButtonFever(). You should have changed that as well.

On another tip, I'm not sure whether you can have form names that include the '-' character. If you do the above and that doesn't work, try replacing '-'
with '_' (underscores).

Kelvin
corlando
Forum Newbie
Posts: 21
Joined: Sun Jun 15, 2003 10:07 pm

Post by corlando »

releasedj, have you ever thought about using this tag?

Code: Select all

<input  type="image" name="submit" src="../images/j_add_to_kart.gif" width="105" height="48" border="0">
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

Yes, this would also be a good method. You don't really need the name attribute either, and so you wouldn't get the x and y variables sent.

Upon reflection, this is probably the method to use for this problem.
It does seem a bit futile to have to have a different form for each item, but I guess that doesn't cause much of a problem.
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

Post by redcircle »

I've intended for the button to appear on every row in a DO WHILE search results situation
bah.. DO WHILE's should be avoided. sloppy coding.[/quote]
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Post by steedvlx »

Problem Solved (kinda)

The final code looks like this if anyone is interested. I even got the popup confirmation window to work right.

Code: Select all

<form name="<?php echo "id_" . $row_rs_kb_prod&#1111;'prod_id_index'];?>" method="get" action="javascript:; "onClick="OpenBrWindow('j_confirm_add.php?prod_id_index=<?php echo $row_rs_kb_prod&#1111;'prod_id_index']?>','cartpop1','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no','610','290','true')"></a> 
              <input name="prod_id_index" type="hidden" id="prod_id_index" value="<?php echo $row_rs_kb_prod&#1111;'prod_id_index']; ?>">
              <input name="Submit" type="image" value="Add to Cart" src="../images/j_add_to_kart.gif" align="absmiddle">
            </form>
Thanks for the direction everyong. That was tough for a newbie.

------------------
SteedVLX
Post Reply