I tried to put a custom code action in the onload event as a Controller and View too but that doesn't work.I tried to put the code in the no-wizzard code but nothing.I need to put it without use the onsubmit event because I need to sent all the data via POST.I can't use the Javascript, I need the PHP cause the MD5 calculation and for some security issues.Can anyone help me?"> [SOLVED] How to add fields into the form TAG with PHP - Forums

Forums

[SOLVED] How to add fields into the form TAG with PHP

stecciu 03 Feb, 2012
I tried to find some answer in all the topics but I didn't find it.

How I can add some fields into the form TAG with the PHP?

I need to insert this code into the tag form:



<?php
echo "<input type=\"hidden\" name=\"MERCHANT_ID\" value=\"" . $merchant_id . "\" id=\"in1\" />\n";
echo "<input type=\"hidden\" name=\"ORDER_ID\" value=\"" . $orderid . "\" id=\"in2\" />\n";
echo "<input type=\"hidden\" name=\"IMPORTO\" value=\"" . $importo . "\" id=\"in3\" />\n";
echo "<input type=\"hidden\" name=\"DIVISA\" value=\"" . $divisa . "\" id=\"in4\" />\n";
echo "<input type=\"hidden\" name=\"ABI\" value=\"" . $abi . "\" id=\"in5\" />\n";
echo "<input type=\"hidden\" name=\"ITEMS\" value=\"" . $items . "\" id=\"in6\" />\n";
echo "<input type=\"hidden\" name=\"URLOK\" value=\"" . $urlok . "\" id=\"in7\" />\n";
echo "<input type=\"hidden\" name=\"URLKO\" value=\"" . $urlko . "\" id=\"in8\" />\n";
echo "<input type=\"hidden\" name=\"MAC\" value=\"" . $topost . "\" id=\"in9\" />";
?>



I tried to put a custom code action in the onload event as a Controller and View too but that doesn't work.
I tried to put the code in the no-wizzard code but nothing.

I need to put it without use the onsubmit event because I need to sent all the data via POST.

I can't use the Javascript, I need the PHP cause the MD5 calculation and for some security issues.
Can anyone help me?
GreyHead 03 Feb, 2012
Hi stecciu,

Where is this data coming from? If you tell me that I may be able to find some code to pass it on.

Bob
stecciu 03 Feb, 2012
i put the data in a custom code in the onload event.
GreyHead 03 Feb, 2012
Hi stecciu,

I see that's where you've put the code but where is, for example, $orderid defined?

Bob
stecciu 03 Feb, 2012
I'm sorry form my short answer but I was writing with the iphone..
I have a form with just a submit button and an hidden box.

In the onload event I have:

Show HTML
Custom code



<?php

$merchant_id = "AAAA";
$orderid = $_GET["id"];
$importo = $_GET["importo"];
$divisa = "EUR";
$abi = "03599";
$key = "AAAAA";
$items = "COD1" . "^" . "DONAZIONE" . "^" . "1" . "^" . $importo . "^" . $divisa . ";";
$urlok = "http://www.xxx.it/donazione-andata-a-buon-fine.html";
$urlko = "http://www.xxx.it/donazione-andata-a-buon-fine-2.html";
$mac = $merchant_id . $order_id . $importo . $divisa . $abi . $items . $key ;
$mac = strtoupper($mac);
$topost = md5($mac);
$topost = strtoupper($topost);


echo "<div class=\"article-header\">\n";
echo "                        <div class=\"module-title\"><div class=\"module-title2\"><div class=\"module-title3\">\n";
echo "                <h2 class=\"title\">\n";
echo "                                        <a href=\"#\">\n";
echo "                        Conferma l'importo</a>\n";
echo "                                    </h2>\n";
echo "            </div></div></div></div>\n";
echo "                        <div class=\"clear\"></div>\n";


echo ("Questo $egrave; l'importo che avete deciso di donare:<h2>" . $importo . "€</h2>Se l'importo è esatto premi il tasto continua altrimenti <a href=\"http://www.progettoarcobaleno.it/collabora-con-noi/fai-una-donazione.html\">CLIKKA QUI</a> per tornare indietro.");


echo "<input type=\"hidden\" name=\"MERCHANT_ID\" value=\"" . $merchant_id . "\" id=\"in1\" />\n";
echo "<input type=\"hidden\" name=\"ORDER_ID\" value=\"" . $orderid . "\" id=\"in2\" />\n";
echo "<input type=\"hidden\" name=\"IMPORTO\" value=\"" . $importo . "\" id=\"in3\" />\n";
echo "<input type=\"hidden\" name=\"DIVISA\" value=\"" . $divisa . "\" id=\"in4\" />\n";
echo "<input type=\"hidden\" name=\"ABI\" value=\"" . $abi . "\" id=\"in5\" />\n";
echo "<input type=\"hidden\" name=\"ITEMS\" value=\"" . $items . "\" id=\"in6\" />\n";
echo "<input type=\"hidden\" name=\"URLOK\" value=\"" . $urlok . "\" id=\"in7\" />\n";
echo "<input type=\"hidden\" name=\"URLKO\" value=\"" . $urlko . "\" id=\"in8\" />\n";
echo "<input type=\"hidden\" name=\"MAC\" value=\"" . $topost . "\" id=\"in9\" />";


?>




The custom code is set as Controller mode.

I need to send the user to another external page with this hidden parameter sent via post but if I did like this the hidden boxes are put out of the form tag. To do the post I can't use the onsubmit event.

Thank you for your help!
stecciu 03 Feb, 2012
I tried to do some hidden boxes and put in the value field this



<?php echo $importo; ?> 




But it doesn't work.
stecciu 03 Feb, 2012
some news? is it possible?
stecciu 04 Feb, 2012
Please help me!!
GreyHead 04 Feb, 2012
Hi stecciu,

Here's a version that seems to work - though you'll need to check through carefully.

In the Form Preview box add a Custom Code element and a Submit Button element. Open the Custom Code element, check the Pure code box and add this HTML:
<div class='article-header'>
	<div class='module-title'>
    	<div class='module-title2'>
        	<div class='module-title3'>
				<h2 class='title'><a href='#'>Conferma l'importo</a></h2>
			</div>
		</div>
	</div>
</div>
<div class='clear'></div>
<div>Questo è l’importo che avete deciso di donare:<h2>{IMPORTO}€</h2>Se l’importo è esatto premi il tasto continua altrimenti <a href='http://www.progettoarcobaleno.it/collabora-con-noi/fai-una-donazione.html'>CLIKKA QUI</a> per tornare indietro.</div>
<input type='hidden' name='MERCHANT_ID' value='' />
<input type='hidden' name='ORDER_ID' value='' />
<input type='hidden' name='IMPORTO' value='' />
<input type='hidden' name='DIVISA' value='' />
<input type='hidden' name='ABI' value='' />
<input type='hidden' name='ITEMS' value='' />
<input type='hidden' name='URLOK' value='' />
<input type='hidden' name='URLKO' value='' />
<input type='hidden' name='MAC' value='' />

In the Events tab drag over a Custom Code action and a Show HTML action.

Open the Show HTML action and Set the Curly Replacer setting to Yes. Save and close it.

Open the Custom Code action and add this code
<?php
$form->data['MERCHANT_ID'] = 'AAA';
$form->data['DIVISA'] = 'EUR';
$form->data['ABI'] = '03599';
$form->data['ORDER_ID'] = JRequest::getVar('id', '', 'get');
$form->data['IMPORTO'] = JRequest::getVar('importo', '', 'get');
$form->data['KEY'] = 'AAAAA';
$form->data['ITEMS'] = "COD1^DONAZIONE^^{$form->data['IMPORTO']}^{$form->data['DIVISA']}";
$form->data['URLOK'] = 'http://www.xxx.it/donazione-andata-a-buon-fine.html';
$form->data['URLKO'] = 'http://www.xxx.it/donazione-andata-a-buon-fine-2.html';
$mac = $form->data['MERCHANT_ID'].$form->data['ORDER_ID'].$form->data['IMPORTO'].$form->data['DIVISA'].$form->data['ABI'].$form->data['ITEMS'].$form->data['KEY'];
$mac = strtoupper($mac);
$form->data['MAC'] = $mac;
$topost = md5($mac);
$form->data['TOPOST'] = strtoupper($topost);
?>

Save and Close the form.

Open the form General tab by clicking the Form Name link in the Forms Manager and set the Submit URL to the URL you need to submit the form to.

Save and test.

If I call the form with a URL including &id=999&importo=ZZZZ then I see these values in the HTML
<div>Questo è l’importo che avete deciso di donare:<h2>ZZZZ€</h2>Se l’importo è esatto premi il tasto continua altrimenti <a href="http://www.progettoarcobaleno.it/collabora-con-noi/fai-una-donazione.html">CLIKKA QUI</a> per tornare indietro.</div>
<input type="hidden" value="AAA" name="MERCHANT_ID">
<input type="hidden" value="999" name="ORDER_ID">
<input type="hidden" value="ZZZZ" name="IMPORTO">
<input type="hidden" value="EUR" name="DIVISA">
<input type="hidden" value="03599" name="ABI">
<input type="hidden" value="COD1^DONAZIONE^^ZZZZ^EUR" name="ITEMS">
<input type="hidden" value="http://www.xxx.it/donazione-andata-a-buon-fine.html" name="URLOK">
<input type="hidden" value="http://www.xxx.it/donazione-andata-a-buon-fine-2.html" name="URLKO">
<input type="hidden" value="AAA999ZZZZEUR03599COD1^DONAZIONE^^ZZZZ^EURAAAAA" name="MAC">


Bob
stecciu 05 Feb, 2012
Thank you Bob, it seems to work!
You're a genius!
This topic is locked and no more replies can be posted.