I have the following code where I am trying to get the 'Finalize Draft Order' submit button to only appear if the 'Create Draft Order' button has been pressed/set. Right now, the button does not show up after I hit the Create Draft Order button. It only displays if I take it out of the if(isset function.
What am I doing wrong?
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="shuffle">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
UPDATE:
$array = array();
while ($row = mysqli_fetch_assoc($query)) {
$array[] = array(
'id' => $row['id'],
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'username' => $row['username'],
'email' => $row['email']
);
if (isset($_POST['shuffle'])) {
}
}
shuffle($array);
echo json_encode($array);
I don't think $_POST['shuffle'] is set. instead of using the submit button for it change your code to:
<form method="POST" name="form">
<input type="hidden" name="shuffle" value="true">
<input type="submit" value="Create Draft Order">
</form>
I'm pretty sure submit's name doesn't count for the POST values.
I don't know what version of PHP meame69 and ScottyMcGready are using, but you very much CAN check to see if the button was clicked by checking for the isset($_POST["submit"]) is true.
http://www.learningaboutelectronics.com/Articles/How-to-check-if-the-submit-button-is-clicked-in-PHP.php
I cannot comment yet, but I will edit this once I figure out what's wrong with Becky's code.
Here's you're issue. Your input button is named shuffle, which is not passed when submitting. If you add a new hidden input element with the name "shuffle" that will pass it through.
edit:
You've said in your question its after the create draft button is pressed. Therefore as per your example:
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="form">
<input type="hidden" name="shuffle" value="1">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
Related
I'm doing a short quiz and i would like to know how can i pass over the quiz answers to the next page?
My Quiz page
<?php
$qtspool =
array( 1=> array('qts'=>'What is my name?', 'ans'=>'Lu'),
2=> array('qts'=>'What is the module code?', 'ans'=>'307'),
3=> array('qts'=>'What is missing char abde?', 'ans'=>'c'),
4=> array('qts'=>'What is missing number 1345?', 'ans'=>'2')
);
$qtspick_key = array_rand($qtspool,3);
for ($i=0; $i<3; $i++)
{
$qtspick_key[$i];
}
$pickqts = array();
$i = 0;
foreach ($qtspick_key as $key)
{
$pickqts[$i] = $qtspool[$key];
$i++;
}
?>
<form method="get" action="abc.php" >
<br>
<?php
foreach($pickqts as $qtsno=>$value)
{
?>
<?php echo $value['qts']; ?>
<input name="user_ans" type="text" >
<input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" />
<br>
<?php
}
?>
<input type="submit"/>
</form>
I tried <input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" /> but it could only pass over the last answer of the question to the next page.
P.S: when I do an echo $value['ans'];, I'm able to return all the answers of the randomized questions on the quiz page.
You have to send variables by array so change the lines:
<input name="user_ans" type="text" >
<input type="hidden" name="answers" value="<?php echo htmlspecialchars($value['ans']); ?>" />
to:
<input name="user_ans[]" type="text" >
<input type="hidden" name="answers[]" value="<?php echo htmlspecialchars($value['ans']); ?>" />
I have 4 different pages both with one form each.
I want to gather all the entries on each of the pages and submit once.
Here is code.
Page 1
<form action="page2" method="POST">
<input type="text" name="sex">
<input type="submit" value="Submit">
</form>
Page 2
<form action="page3" method="POST">
<input type="text" name="size">
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 3
<form action="page4" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="verNote.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" > <input type="submit" value="Submit">
</form>
Then i will like to get all the infos on verNote.php
<?php
echo $_POST['sex'];
echo '<br>';
echo $_POST['size'];
echo '<br>';
echo $_POST['color'];
echo '<br>';
echo $_POST['likes'];
?>
This code above dont seem to post entries from both pages 1 and 2, just for 3 and 4 alone gets submitted.
Will appreciate immediate assistance form anyone who understands my question.
Regards!
You need to load the hidden fields again each time
Page 3
<form action="B.php" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="B.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
I didn't understand 100% what you're trying to achieve, but have you tried using sessions?
Do this in B.php:
<?php
session_start();
if( isset($_POST['sex']))
$_SESSION['sex'] = $_POST['sex'];
if( isset($_POST['size']))
$_SESSION['size'] = $_POST['size'];
if( isset($_POST['color']))
$_SESSION['color'] = $_POST['color'];
if( isset($_POST['likes']))
$_SESSION['likes'] = $_POST['likes'];
?>
Then you can retrieve the values from any other file, just call session_start(); and use the $_SESSION superglobal.
EDIT
Using sessions, you verNote.php file could be something like this:
<?php
session_start();
echo $_SESSION['sex'];
echo '<br />';
echo $_SESSION['size'];
echo '<br />';
echo $_SESSION['color'];
echo '<br />';
echo $_SESSION['likes'];
echo '<br />';
?>
So i need a way to be able to echo $row['username'] and echo $row['password'] where the id is specified.
So example is i have 3 rows i need to get information from with id numbers 20, 56, 88.
Now i have made the query $query = "SELECT * FROM Card_File WHERE id = $id";
How do i echo this data (keeping in mind its not in a table and could be placed in random location on the webpage, and the forms the outputs will be going into will be different (eg, not got the same form field names.))
echo $row['username'] $id=20;
echo $row['password'] $id=20;
echo $row['username'] $id=56;
echo $row['password'] $id=56;
echo $row['username'] $id=88;
echo $row['password'] $id=88;
I have been looking arround and seen some very complicated examples but dont belive its that hard to echo a row by id. I may be wrong
Below is not a great example of what the ends result is but would give you an idea.
<!DOCTYPE html>
<html>
<head>
<?php
// Connect to the database
$link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
// Select table and arguments
$query = "SELECT * FROM Card_File WHERE id = $id";
$result = mysqli_query($link, $query);
?>
</head>
<body>
<?php foreach($row = mysqli_fetch_array($result)): ?>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=20 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=20 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=56 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=56 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=88 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=88 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<?php endforeach; ?>
</body>
</html>
I believe this is what you want to do.
<?php
$ids_tofind = array(1,6,3); //for example
$id = implode(",",$ids_tofind);
$link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
// Select table and arguments
$query = "SELECT * FROM Card_File WHERE id IN(". $id.")";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){;?>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<?php };?>
This will echo out the form for all three users with ID 1, 6 and 3.
I want add changing on category page, I customize page websitelink.com/components\com_virtuemart\themes\default\templates\browse\browse_3.php
I add code
<div class="addtocart_buttonList">
<?php
$button_lbl = $VM_LANG->_('PHPSHOP_CART_ADD_TO');
$button_cls = 'addtocart_button';
if( CHECK_STOCK == '1' && ( $product_in_stock < 1 ) ) {
$button_lbl = $VM_LANG->_('VM_CART_NOTIFY');
$button_cls = 'notify_button';
$notify = true;
} else {
$notify = false;
}
?>
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
</div>
After adding this line add to cart button appear on list items, but than i click on add to cart button error will come
Please enter a valid quatity for this item
How i can solve this?
You need to specify a quantity as an input field, hidden or otherwise. We only wanted the customer to be able to order one of an item, so added this code:
<input type="hidden" value="1" name="quantity">
Having that named input field satisifed the Virtuemart validation.
How do I integrate paybox system to handle deferred payment?
I learned that PBX_DIFF parameter is used to mention no. of days to delay the transaction. Thats exactly what I wanted. But there seems no working code for php with deferred payment for Paybox.
The following code is working fine without mentioning the deferred payment parameter (PBX_DIFF). But when I add that parameter, its not working
<form name="paybox_frm" id="paybox_frm" method="GET" action="<?php echo $payboxUrl;?>">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?PHP echo $MONTANT;?>">
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?PHP echo $REFERENCE;?>">
<input type="hidden" name="PBX_PORTEUR" value="<?PHP echo $PORTEUR;?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR;?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH;?>">
<input type="hidden" name="PBX_TIME" value="<?PHP echo $datetime;?>">
<input type="hidden" name="PBX_HMAC" value="<?PHP echo $pbx_hmac;?>">
<!-- Code added for return url-->
<input type="hidden" name="PBX_REFUSE" value="<?PHP echo $PBX_REFUSE;?>" />
<input type="hidden" name="PBX_ANNULE" value="<?PHP echo $PBX_ANNULE;?>" />
<input type="hidden" name="PBX_EFFECTUE" value="<?PHP echo $PBX_EFFECTUE;?>" />
<input type="hidden" name="PBX_LANGUE" value="<?PHP echo $PBX_LANGUE;?>" />
Any help greatly appreciated. Thanks in advance.
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12"
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>