Jump to content


Photo

Question about "hidden" form fields


  • Please log in to reply
3 replies to this topic

#1 supergrover1981

supergrover1981
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 October 2006 - 07:42 AM

Gidday guys,

I'm trying to write a php script that takes the values from text input fields, and if the values are over a certain quantity, posts them as hidden variables to a 3rd-party site. Sample of the current code looks like this:

 <?php
		         $prodlistcount = 0;
			 $hicarbqty = htmlentities($_POST['hicarbqty']);		  
			 $hiefiqty = htmlentities($_POST['hiefiqty']);
			 ?>

...

<?php

if ($hicarbqty > 0) {
$prodlistcount++;
echo "<input type='hidden' name='item_name_$prodlistcount' value='Hiclone Fuel Efficiency Device'>
;}

if ($hiefiqty > 0) {
$prodlistcount++;
echo "<input type='hidden' name='item_name_$prodlistcount' value='HiClone (For EFI)'>
;}
?>


What I would like to do is take input values *from the same page* as this PHP, instead of posting it from the prior page. Does anyone know if/how this can be done? Any help would be very appreciated.

Lotsa thanks gang,
                        - JB

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 17 October 2006 - 08:17 AM

your question isn't totally clear.  are you asking if there's anyway to send these hidden input values to the third party script (i assume paypal or something similar) directly from the form that their quantities are input on?

#3 supergrover1981

supergrover1981
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 October 2006 - 08:38 AM

*grin* Hi Akitchin - thanks for the quick response. :-)

Yes, you're right - I'd like to send input values to paypal directly from the form that their quantities are input on.


The difficult part is that I only want to send input values that satisfy a conditional, so instead of just outputting the form to paypal, I need to:

1.) Take the variable entered into the form and evaluate it
2.) If the variable satisfies a condition, send that variable to paypal

I can do this over 2 forms via the "post" command, but ideally I'd like to do it from just the single form. Any help most appreciated. :-)

Cheers,
        - JB



#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 18 October 2006 - 04:26 AM

unfortunately i'm not sure there's a reliable way of doing this.  to intercept the POST variables BEFORE the form is sent requires javascript; the problem there is that javascript cannot be relied upon to do requisite work for a variety of reasons (the primary being that it is client-side, and thus can be disabled, fudged with, etc.)

you COULD take the POST variables once the form is sent, add the required variables to the POST array directly, and construct a manual POST request to the paypal target.  this won't emulate the typical form POST though, in that it's hard to construct a manual POST request while also forwarding the user to the target.

i guess what i'm trying to say is that coming from experience (i've tried dealing with this exact scenario before) it's probably a lot less leg(finger?)work to just issue a "confirmation" page which creates the hidden inputs, as you're currently doing.  perhaps someone else can shed more light, though.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users