I'm creating a form in html, I can update per data, but I want to update all data by one click?
<?php foreach($queryRecords as $res) :?>
<tr>
<form action="" method="POST" name="form" id="form">
<td>
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $res["id"];?>">
<input name="gp_name" type="hidden" class="normalinput" id="gp_name" value="<?php echo $res["gp_name"];?>">
<input name="date" type="hidden" class="normalinput" id="date" size="10" value="<?php echo $res["date"];?>">
<input name="day" type="hidden" class="normalinput" id="day" size="1" value="<?php echo $res['day'];?>">
<input name="starting_time" type="hidden" class="normalinput" id="starting_time" size="9" value="<?php echo $res["starting_time"];?>">
<input name="type" type="hidden" class="normalinput" id="type" size="4" value="<?php echo $res["type"];?>">
<input name="duration" type="hidden" class="normalinput" id="duration" size="4" value="<?php echo $res["duration"];?>">
<input name="checkin" type="hidden" class="normalinput" id="checkin" size="8" value="<?php echo $res["checkin"];?>">
<input name="checkout" type="hidden" class="normalinput" id="checkout" size="8" value="<?php echo $res["checkout"];?>">
<input name="country" type="hidden" class="normalinput" id="country" size="7" value="<?php echo $res["country"];?>">
<input name="city" type="hidden" class="normalinput" id="city" size="6" value="<?php echo $res["city"];?>">
<input name="supplier" type="hidden" class="normalinput" id="supplier" size="8" value="<?php echo $res["supplier"];?>">
<input name="arrange" type="hidden" class="normalinput" id="arrange" size="10" value="<?php echo $res["arrange"];?>">
<input name="no_of_day" type="hidden" class="normalinput" id="no_of_day" size="1" value="<?php echo $res["no_of_day"];?>">
<input name="qua" type="hidden" class="normalinput" id="qua" size="1" value="<?php echo $res["qua"];?>">
<input name="cost" type="hidden" class="normalinput" id="cost" size="6" value="<?php echo $res["cost"];?>">
<input name="profit_rate" type="hidden" class="normalinput" id="profit_rate" size="4" value="<?php echo $res["profit_rate"];?>">
<input name="currency_rate" type="hidden" class="normalinput" id="currency_rate" size="4" value="<?php echo $res["currency_rate"];?>">
<input name="eurbuy" type="hidden" class="normalinput" id="eurbuy" size="4" value="<?php echo $res["eurbuy"];?>">
<input name="vat" type="hidden" class="normalinput" id="vat" size="4" value="<?php echo $res["vat"];?>">
<input name="pprice" type="hidden" class="normalinput" id="pprice" size="4" value="<?php echo round( $res["cost"] * $res["profit_rate"] * $res["currency_rate"] / $res["eurbuy"],0) ;?>">
<input name="total" type="hidden" class="normalinput" id="total" value="<?php echo round( $res["pprice"] * $res["no_of_day"] * $res["qua"] ,0) ;?>">
<input name="reference" type="hidden" class="normalinput" id="reference" size="10" value="<?php echo $res['reference'];?>">
<input name="supplement_rate" type="hidden" class="normalinput" id="supplement_rate" size="5" value="<?php echo $res["supplement_rate"];?>">
<input name="supplement" type="hidden" class="normalinput" id="supplement" size="5" value="<?php echo round( $res["supplement_rate"] * $res["profit_rate"] * $res["no_of_day"] * $res["currency_rate"] / $res["eurbuy"],0) ;?>">
<button class="btn btn-info" type="button" onClick="update(form); window.location.reload();"><i class="fas fa-edit"></i></button>
<button class="btn btn-danger" type="button" onClick="window.location.href='gp_delete.php?id=<?php echo $res['id'];?>'"><i class="fas fa-trash-alt"></i></button>
</td>
</form>
</tr><?php endforeach;?>
since I need to update per data, how do you create one button to update all data for the table?
document.querySelector('form').addEventListener('submit', (e) => {
const formData = new FormData(e.target);
// Now you can use formData.get('foo'), for example.
// Don't forget e.preventDefault() if you want to stop normal form .submission
});
This is a nitpicky answer, but let me explain why this is a better solution:
We're properly handling a form submit rather than a button press. Some people like to push enter on fields. Some people use alternative input devices such as speech input or other accessibility devices. Handle the form submit and you correctly solve it for everyone.
We're digging into the form data for the actual form that was submitted. If you change your form selector later, you don't have to change the selectors for all the fields. Furthermore, you might have several forms with the same input names. No need to disambiguate with excessive IDs and what not, just track the inputs based on the form that was submitted. This also enables you to use a single event handler for multiple forms if that is appropriate for your situation.
The FormData interface is fairly new, but is well supported by browsers. It's a great way to build that data collection to get the real values of what's in the form. Without it, you're going to have to loop through all the elements (such as with form.elements) and figure out what's checked, what isn't, what the values are, etc. Totally possible if you need old browser support, but the FormData interface is simpler.
I'm using ES6 here... not a requirement by any means, so change it back to be ES5 compatible if you need old browser support.
Related
I have a PayPal payment gateway like this,
<form action="https://secure.paypal.com/uk/cgi-bin/webscr" method="post" name="paypal" id="paypal">
<!-- Prepopulate the PayPal checkout page with customer details, -->
<input type="hidden" name="first_name" value="<?php echo Firstname?>">
<input type="hidden" name="last_name" value="<?php echo Lastname?>">
<input type="hidden" name="email" value="<?php echo Email?>">
<input type="hidden" name="address1" value="<?php echo Address?>">
<input type="hidden" name="address2" value="<?php echo Address2?>">
<input type="hidden" name="city" value="<?php echo City?>">
<input type="hidden" name="zip" value="<?php echo Postcode?>">
<input type="hidden" name="day_phone_a" value="">
<input type="hidden" name="day_phone_b" value="<?php echo Mobile?>">
<!-- We don't need to use _ext-enter anymore to prepopulate pages -->
<!-- cmd = _xclick will automatically pre populate pages -->
<!-- More information: https://www.x.com/docs/DOC-1332 -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="paypal#email.com" />
<input type="hidden" name="cbt" value="Return to Your Business Name" />
<input type="hidden" name="currency_code" value="GBP" />
<!-- Allow the customer to enter the desired quantity -->
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="Name of Item" />
<!-- Custom value you want to send and process back in the IPN -->
<input type="hidden" name="custom" value="<?php echo session_id().?>" />
<input type="hidden" name="shipping" value="<?php echo $shipping_price; ?>" />
<input type="hidden" name="invoice" value="<?php echo $invoice_id ?>" />
<input type="hidden" name="amount" value="<?php echo $total_order_price; ?>" />
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/thankyou"/>
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/cancelled" />
<!-- Where to send the PayPal IPN to. -->
<input type="hidden" name="notify_url" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/process" />
</form>
Can I upgrade this to PSD2?
https://www.paypal.com/uk/webapps/mpp/psd2-new
If so, how do I integrate it?
thanks in advance. I am building a custom payment gateway for woocommerce. The thing i am struggling with is that the server of my payment gateway only accepts request when i submit a form. So i do form submit with redirect to payment gateway url. The problem is that woocommerce is not executing my form.submit in process_payment method.
So i tried using wp_remote_post, using curl but none of these work for me because i need to redirect to my payment gateway with data, as if in form.submit.
public function process_payment( $order_id ) {
global $woocommerce;
// Get this Order's information so that we know
// who to charge and how much
$customer_order = new WC_Order( $order_id );
//Here i take some data and put it inside $a
echo '<form name="customForm" action="https://gateway.com/web" method="post" id="customForm">
<input type="hidden" name="token" id="token" value="<?php echo $token;?>">
<input type="hidden" name="key" id="key" value="<?php echo $a->key;?>">
<input type="hidden" name="callbackUrl" id="callbackUrl" value="<?php echo $a->callbackUrl;?>">
<!-- callback url where alif sends information about status of transactions -->
<input type="hidden" name="returnUrl" id="returnUrl" value="<?php echo $a->returnUrl;?>">
<input type="hidden" name="amount" id="amount" value="<?php echo $a->amount;?>" required>
<input type="hidden" name="orderId" id="orderId" value="<?php echo $a->orderid;?>">
<input type="hidden" name="info" id="info" value="<?php echo $a->info;?>">
<input type="hidden" name="email" id="email" value="<?php echo $a->email;?>">
<input type="hidden" name="phone" id="phone" value="<?php echo $a->phone;?>">
</form>';
?><script type="text/javascript">
document.getElementById('customForm').submit();
</script><?php
}
I expected to be redirected to payment gateway url, but i dont get redirected and get invalid form message in woocommerce.
I think you need first create hook filter like this:
add_filter('woocommerce_receipt_' . $this->id, array(&$this, 'receipt_page'));
And then:
public function receipt_page($order_id)
{
// Get this Order's information so that we know
// who to charge and how much
$customer_order = new WC_Order($order_id);
//Here i take some data and put it inside $a
echo '<form name="customForm" action="https://gateway.com/web" method="post" id="customForm">
<input type="hidden" name="token" id="token" value="<?php echo $token;?>">
<input type="hidden" name="key" id="key" value="<?php echo $a->key;?>">
<input type="hidden" name="callbackUrl" id="callbackUrl" value="<?php echo $a->callbackUrl;?>">
<!-- callback url where alif sends information about status of transactions -->
<input type="hidden" name="returnUrl" id="returnUrl" value="<?php echo $a->returnUrl;?>">
<input type="hidden" name="amount" id="amount" value="<?php echo $a->amount;?>" required>
<input type="hidden" name="orderId" id="orderId" value="<?php echo $a->orderid;?>">
<input type="hidden" name="info" id="info" value="<?php echo $a->info;?>">
<input type="hidden" name="email" id="email" value="<?php echo $a->email;?>">
<input type="hidden" name="phone" id="phone" value="<?php echo $a->phone;?>">
</form>';
}
I think the issue with wrong syntax. Try using this syntax:
echo <<<HTML
<form name="customForm" action="https://gateway.com/web" method="post" id="customForm">
<input type="hidden" name="token" id="token" value="{$token}">
<input type="hidden" name="key" id="key" value="{$a->key}">
<input type="hidden" name="callbackUrl" id="callbackUrl" value="{$a->callbackUrl}">
<!-- callback url where alif sends information about status of transactions -->
<input type="hidden" name="returnUrl" id="returnUrl" value="{$a->returnUrl}">
<input type="hidden" name="amount" id="amount" value="{$a->amount}" required>
<input type="hidden" name="orderId" id="orderId" value="{$a->orderid}">
<input type="hidden" name="info" id="info" value="{$a->info}">
<input type="hidden" name="email" id="email" value="{$a->email}">
<input type="hidden" name="phone" id="phone" value="{$a->phone}">
</form>
<script type="text/javascript">
document.getElementById('customForm').submit();
</script>
HTML;
i want to get the textfield value and assign it for the radio button value
my code is working but not from the first time
after the first submit it will work perfectly
how do i make it work from the first page load
here is my code
<input type="text" name="optionAtxt" value="<?php echo #$_POST['optionAtxt'] ?>" /> <input type="radio" name="option" required value="<?php echo #$_POST['optionAtxt'] ?>">
<input type="text" name="optionBtxt" value="<?php echo #$_POST['optionBtxt'] ?>" /> <input type="radio" name="option" value="<?php echo #$_POST['optionBtxt'] ?>">
<input type="text" name="optionCtxt" value="<?php echo #$_POST['optionCtxt'] ?>"/> <input type="radio" name="option" value="<?php echo #$_POST['optionCtxt'] ?>">
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="1" />
<?php
if (isset($_POST['submitted'])) {
$selected = trim($_POST['option']);
echo $selected;
}?>
I have no any idea about it. I serched my sites but i can't find solutions.
My requirement is that, my query fetches bank account number from database,
For example, there r one record given by my query then i want to send money to this bank account.
what should i do??? Which api use for me??
My code is given below:
$queryOperator = "SELECT * FROM operatortransaction AS ot LEFT JOIN paymenttransaction AS pt ON
ot.OperatorID != pt.OperatorID WHERE ot.IsPaymentRequest = 1 AND ot.Amount != pt.Amount ";
$arrOperator = $obj->select($queryOperator);
$count = 0;
if(!empty($dataOperator))
{
foreach($arrOperator as $operator)
{
if($arrOperator[$count]['Amount'] >= $arrOperator[$count]['RequestAmount'])
{
$queryDetail = "SELECT * FROM operatorprofile WHERE UserID = '$arrOperator[$count]['OperatorID']' ";
$Data = $obj->select($queryDetail);
// i want to put api code here......//
}
}
}
Thanks.
Hi you can try to use PayPal Xclick
<form action="https://secure.paypal.com/uk/cgi-bin/webscr" method="post" name="paypal" id="paypal">
<!-- Pre Populate the Paypal Checkout Page With Customer Details, -->
<input type="hidden" name="first_name" value="<?php echo Firstname?>">
<input type="hidden" name="last_name" value="<?php echo Lastname?>">
<input type="hidden" name="email" value="<?php echo Email?>">
<input type="hidden" name="address1" value="<?php echo Address?>">
<input type="hidden" name="address2" value="<?php echo Address2?>">
<input type="hidden" name="city" value="<?php echo City?>">
<input type="hidden" name="zip" value="<?php echo Postcode?>">
<input type="hidden" name="day_phone_a" value="">
<input type="hidden" name="day_phone_b" value="<?php echo Mobile?>">
<!-- We dont need to use _ext-enter anymore to prepopulate pages -->
<!-- cmd = _xclick will automatically pre populate pages -->
<!-- More Info: https://www.x.com/docs/DOC-1332 -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="paypal#email.com" />
<input type="hidden" name="cbt" value="Return to Your Business Name" />
<input type="hidden" name="currency_code" value="GBP" />
<!-- Allow customer to enter desired quantity -->
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="Name of Item" />
<!-- Custom Value You want to send and process back in the IPN -->
<input type="hidden" name="custom" value="<?php echo session_id().?>" />
<input type="hidden" name="shipping" value="<?php echo $shipping_price; ?>" />
<input type="hidden" name="invoice" value="<?php echo $invoice_id ?>" />
<input type="hidden" name="amount" value="<?php echo $total_order_price; ?>" />
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/thankyou"/>
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/cancelled" />
<!-- Where to send the paypal IPN to. -->
<input type="hidden" name="notify_url" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/process" />
NOTICE
Do remember to make a very strong VALIDATION!!!
<form class="formp" action="" method="post" enctype="multipart/form-data" id="frm" name="wjd">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"/>
<p>Gerecht:</p><p>Prijs:</p><p>Plaatje:</p><p>Upload:</p>
<?php
$resultmenus = mysqli_query($dbc,"SELECT * FROM prijslijst WHERE menunaam='menu\'s'");
while($rowmenus = mysqli_fetch_array($resultmenus,MYSQLI_ASSOC)) {
echo "<input type=\"hidden\" name=\"id\" value=\"{$rowmenus['id']}\"/>";
echo "<input name=\"gerecht[]\" type=\"text\" size=\"30\" maxlength=\"30\" value=\"{$rowmenus['gerecht']}\"/>";
echo "<input name=\"prijs[]\" type=\"text\" size=\"5\" maxlength=\"5\" value=\"{$rowmenus['prijs']}\"/>";
echo "<img src=\"../{$rowmenus['plaatje']}\" /><input size=\"1\" type=\"file\" name=\"file[]\" id=\"file\"/>";
}
<input type="submit" name="submit" value="verzend" />
</form>
This will output a form with id's 1 to 5 from the db echo'd in the hidden input type field.
My question is: when i upload only 1 file in row 3 with id3 and the rest are empty, is it possible to retrieve only that id?
Because when i try to retrieve it with $_POST['id']; I get the last value which is 5.The is the output to the browser.
<form id="frm" class="formp" name="wjd" enctype="multipart/form-data" method="post" action="">
<input type="hidden" value="2000000" name="MAX_FILE_SIZE">
<p>Gerecht:</p><p>Prijs:</p><p>Plaatje:</p><p>Upload:</p>
<input type="hidden" value="1" name="id">
<input type="text" value="Menu 1" maxlength="30" size="30" name="gerecht[]">
<input type="text" value="3.00" maxlength="5" size="5" name="prijs[]">
<img src="../images/plaatjes/mini_menu3.gif">
<input id="file" type="file" name="file[]" size="1">
<input type="hidden" value="2" name="id">
<input type="text" value="Menu 2" maxlength="30" size="30" name="gerecht[]">
<input type="text" value="6.00" maxlength="5" size="5" name="prijs[]">
<img src="../images/plaatjes/mini_menu2.gif">
<input id="file" type="file" name="file[]" size="1">
<input type="hidden" value="3" name="id">
<input type="text" value="Menu 3" maxlength="30" size="30" name="gerecht[]">
<input type="text" value="6.00" maxlength="5" size="5" name="prijs[]">
<img src="../images/plaatjes/mini_menu1.gif">
<input id="file" type="file" name="file[]" size="1">
<input type="hidden" value="4" name="id">
<input type="text" value="Menu 4" maxlength="30" size="30" name="gerecht[]">
<input type="text" value="7.00" maxlength="5" size="5" name="prijs[]">
<img src="../images/plaatjes/mini_menu3.gif">
<input id="file" type="file" name="file[]" size="1">
<input type="hidden" value="5" name="id">
<input type="text" value="Menu 5" maxlength="30" size="30" name="gerecht[]">
<input type="text" value="4.00" maxlength="5" size="5" name="prijs[]">
<img src="../images/plaatjes/mini_menu2.gif">
<input id="file" type="file" name="file[]" size="1">
<input type="submit" value="verzend" name="submit">
</form>
This is the handling script.
if(isset($_POST['submit'])) {
if((array_search('', $_POST["gerecht"])!==false) or (array_search('', $_POST["prijs"])!==false)) { //1 or more field empty
echo "<span class=\"error\">Please fill in all fields</span>";
exit();
}else{//field filled in
foreach ($_FILES['file']['name'] as $i => $name) {
if ($_FILES['file']['error'][$i] == 4) { // no upload continue
continue;
}
if ($_FILES['file']['error'][$i] == 0) {
echo $_POST['id'];
}//end else error 0
}//end foreach
}//end filled in forms
}else{ //submit button clicked
}
if you re-use a form element name (and it's not an array) the last value will overwrite previous values. See how you have
<input type="hidden" value="5" name="id">
try instead
<input type="hidden" value="5" name="id[]">
and iterate through them.
You have
<input type="hidden" value="1" name="id">
<input type="hidden" value="2" name="id">
etc.
You're going to only get number 5 because it is the last one, and is overwriting the one before it.
Same with the input texts, the name attribute should be different.
Do a var_dump($_POST); to see all that is being POST'ed.