Page 1 of 1

Trying to POST data from a "repeating" form field

Posted: Tue Jun 17, 2003 6:30 am
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

Posted: Tue Jun 17, 2003 8:12 am
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']; ?>">

Posted: Tue Jun 17, 2003 10:33 am
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

Posted: Tue Jun 17, 2003 10:38 am
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'.

Posted: Tue Jun 17, 2003 10:48 am
by corlando
just a thought...why not use this.form?

Code: Select all

onclick="formButtonFever(this.form,'submit')

Posted: Tue Jun 17, 2003 10:56 am
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

Posted: Tue Jun 17, 2003 11:07 am
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

Posted: Tue Jun 17, 2003 11:53 am
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

Posted: Tue Jun 17, 2003 11:59 am
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

Posted: Tue Jun 17, 2003 12:45 pm
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">

Posted: Tue Jun 17, 2003 3:30 pm
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.

Posted: Tue Jun 17, 2003 5:25 pm
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]

Posted: Wed Jun 18, 2003 12:52 am
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