Make a search form to search with http api - http

i am new to this matter. I am trying to create a search form, that allows searching a database via http api and display the result on a website. The call requires authorization:
$headers = array ('headers' => array(
'Authorization' => 'bearer' . $token ,
'Content-type' => 'application/json',
'Accept' => 'application/json'));
My search form looks like this:
<form method="GET" accept="application/json" action="https://example.xx/api/v1/products?page=1&size=5&direction=asc&search=value">
<input type="text" name="search" size="40" maxlength="256" value="" placeholder="testsearch">
<input type="submit" name="search_button" value="Search">
</form>
When i enter something into the input field and hit the submit button, the browser displays:
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
And in the browsers address field i see:
https://example.xx/api/v1/products?search=testvalue&search_button=Search
Obviously the authorisation is ignored and the url shows that i have left my website.
Do i have to make this work with an action="somephp.php"?
How can i authorize the call from the form and display the response in a website?
Hints much appreciated. theo

Thanks to the german wordpress forum, i found the answer –
The Form:
<form method="post" id="api-result-searchform" action="">
<input type="text" class="search" placeholder="<?php echo esc_attr_x( 'Author?', 'placeholder' ) ?>" value="" name="searchauthor" id="s" title="api-search" />
<input class="button"type="submit" name="search_button" value="Search">
</form>
And the call:
<?php
$searchterm = $_POST['searchauthor'];
$url = 'https://example.de/api/v1/product?search=ti=' . $searchterm;
$response = wp_remote_get($url, $headers);
//etc.
This works well.

Related

How to perform Opayo Integration using PHP

I'm trying to add integration with Opayo payment on website.
The form
I just have this code:
I change card and card holder details for security reason
$text ='Description=Finishing transaction&Currency=GBP&VendorTxCode=22013115512924219800&amount=5.00&BillingSurname=Paul&BillingFirstnames=Smith&BillingAddress1=ddd&BillingCity=London&BillingPostCode=BH99PU&BillingCountry=GB&DeliveryState=&DeliverySurname=Jhon&DeliveryFirstnames=Jhon&DeliveryAddress1=ddd&DeliveryCity=London&DeliveryPostCode=BH99PU&BillingState=&DeliveryCountry=GB&VendorData=Testing Data &ApplyAVSCV2=2&referid=&language=&website=&Phone=SendEmail=&CardHolder=Smith Alves Gomety&Cardnumber=5434391244446116&ExpiryDate=1229&CardType=MC';
$key = "yuG4B75PE2Gaqgus";
$iv = hex2bin('00000000000000000000000000000000');
$ciphertext_raw = openssl_encrypt($text , "AES-128-CBC", $key , OPENSSL_RAW_DATA, $iv);
$hex = bin2hex($ciphertext_raw);
$hex ='#' . $hex;
<form method="POST" id="SagePayForm" action="https://test.sagepay.com/gateway/service/vspform-register.vsp">
<input type="hidden" name="VPSProtocol" value= "4.00">
<input type="hidden" name="TxType" value= "PAYMENT">
<input type="hidden" name="Vendor" value= "xxxxxxxxxxxxxxx">
<input type="hidden" name="Crypt" value= "<?php echo $hex; ?>">
<input type="submit" value="continue to SagePay">
</form>
The page comes like following
Page generated
And, when I click on "Continue to SagePay" I'm receiving the following
Ssubmiting result
Does anyone can help me with this?
How to integrate in my own form or on SagePay?
Does anyone has full PHP code to this integration including returnings codes,,,,

How to I connect a search form field with an API GET request? (Wordpress)

On my home page, I have the html form:
<form>
<input type="text" name="condition" placeholder="condition" value="condition" />
<input type="submit" value="search NOW" class="search-btn" />
</form>
On the page that needs to return the results (/yacht-search), I have the wp_remote_get call:
$response = wp_remote_get('http://data.yatco.com/dataservice/APIKEY/search' );
How do I link the two so that when the user enters the condition ("new" for example) - it connects to the API and returns the results?
I've tested the API call in Postman and it returns the data just fine - I just am having trouble connecting the dots so it outputs the results onto the page..
$response = wp_remote_get('http://data.yatco.com/dataservice/APIKEY/search' );
$api_response = json_decode( wp_remote_retrieve_body( $response ), true );

set curect address to <form action=">

i create simple plugin wordpress , one validationform.php and rflinsertdb.php
when user click on submit form , i want got rflinsertdb.php the page validation and insert information to db , but wordpress give me Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
this 2 php page in one folder that name in public ,i see to many codes in internet but not help, how can i do that ?
thx alot
i try this codes for action form
<form method="post" action="<?php bloginfo('template_url'); ?>/rflInsertdb.php">
<p id="errorMessage"></p>
<p>name: <input type="text" class="register" name="name" id="name"></p>
<p>family: <input type="text" class="registerForm" id="family" name="family"></p>
<p>numbers :<input type="number" class="registerForm" id="numbers" name="numbers" min="1" max="200" value="1"></p>
<p>tell: <input type="text" class="registerForm" id="tell" name="tell"></p>
<p><input type="submit" value="ثبت" class="registerForm" id="submit" name="submit"></p>
</form>
This happens to you, because you are using template directory for: /rflInsertdb.php
Try to use
<form method="post" action="<?php echo plugin_dir_url( __FILE__ ); ?>/rflInsertdb.php">
If your file is under the public (what is under the plugin dir), then maybe:
<form method="post" action="<?php echo plugin_dir_url( __FILE__ ); ?>/public/rflInsertdb.php">
See here: https://codex.wordpress.org/Function_Reference/plugin_dir_url

wordpress custom contact form html + php inside page

hi everybody i have my contact form ready in html and php (2 different files one html and one php file) and i want to use it in a worpress page.
the user fills the form, selects support department answers the captcha and presses submit button. the form sends all the form data through email to the administrator, a thank you email to the user and redirects to a thank you page.
the html form is
<html>
<body>
<head>
<script src="http://www.google.com/recaptcha/api.js" async defer> </script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<i>Use the form to get in touch with us.</i>
<form action="form.php" method="POST">
<strong>Name:*</strong>
<input style="width:300px;" name="username" type="text" required />
<strong>E-mail Adress:*</strong>
<input style="width:300px;" name="useremail" type="text" required />
<strong>Subject:*</strong>
<input style="width:300px;" name="usersubject" type="text" required />
<strong>Message:*</strong>
<textarea style="width:300px;" cols="40" name="usermessage" rows="5" required></textarea>
<strong>Select Support Department </strong>
<select name="support">
<option style="width:200px;" value="" >Choose Service</option>
<option style="width:200px;" value="support#xxxxxxxx.com" required>Technical support</option>
<option style="width:200px;" value="sales#xxxxxxxxxx.com" required>Sales</option>
<option style="width:200px;" value="info#xxxxxxxxxxx.com" required>Press</option>
<option style="width:200px;" value="info#xxxxxxxxxxx.com" required>Other</option>
</select>
//recaptcha
<div class="g-recaptcha" data- sitekey="------my site key---------"></div>
<input type="submit" value="send" name="submit"/>
//it redirects when you hit submit
<?php
if ( isset( $_POST['submit'] ) ){
header("Location:http://xxxxxxxxx.com/thank-you-messasge/");
}
?>
</form>
</html>
</body>
my form.php is
<?
//set up the message for administrator
$msg="Name:".$_POST["username"]."\n";
$msg .="E-mail:".$_POST["useremail"]."\n";
$msg .="Subject:".$_POST["usersubject"]."\n";
$msg .="Usermessage:".$_POST["usermessage"]."\n";
//set up message for customer
$msg_customer="We received your request and we will answer you within 24 hours.";
$msg_customer.="\n"."xxxxxxxxxxxxxx";
//set up the email for the administrator
$recipient=$_POST["support"];
$subject= "Support Contact Form ";
$mailheaders="From: xxxxxxxx sales#xxxxxxxxx.com \n";
//set up the email for the customer
$recipient_customer=$_POST["useremail"];
$subject_customer= "Support Contact Form ";
$mailheaders_customer="From: xxxxxxxxxx sales#xxxxxxxxxxxxxxx.com \n";
//send the emails
mail($recipient,$subject,$msg, $mailheaders);
mail($recipient_customer,$subject_customer,$msg_customer, $mailheaders_customer);
?>
i want this form to appear in one page and be able to run the php code when the submit button is pressed.
i cannot run the form.php file even if i save it on the root directory.
it seems i am loosing something
thank you very much
To troubleshoot your form, press F12 in your browser to access the developer tools menu, and take a look at what happens on the Network panel when you submit the form. This should give you some clues about what is failing.
Also, you should not be using unfiltered $_POST variables directly, e.g.:
$name = sprintf("Name:%s\n", filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) );
i found out the way:
i copy/pasted the html form inside the page code view and i linked absolutely to my php file
<form action="http://example.com/php_file_directory/form.php" method="POST">

File upload not working using URLRequest in flex

I used upload functionality by html . using given code it's working fine .
<form id="avatar" enctype="multipart/form-data"
action="http://localhost:8080/alfresco/service/slingshot/profile/uploadavatar?
alf_ticket=TICKET_7475e180e8d258c0341fc745a3a35274d0a06e50"
method="post">
<input type="text" name="username" value="ken"/>
Select a file:
<input type="file" name="filedata" />
<input type="submit" name="button" value="upload" / /form
Same functionality I have tried in flex :
var uploadURL:URLRequest = new URLRequest();
uploadURL.url="http://localhost:8080/alfresco/service/slingshot/profile/uploadavatar?alf_ticket=TICKET_7475e180e8d258c0341fc745a3a35274d0a06e50"";
uploadURL.method=URLRequestMethod.POST;
uploadURL.contentType="multipart/form-data";
var params:URLVariables = new URLVariables();
params.username ="admin";
params.filedata=fileRef.data;
uploadURL.data = params;
fileRef.upload(uploadURL)
BUT GETTING Bad request error . so anybody know , what did i wrong in code . Please share with me .
In a POST request you are trying to send a parameter in URL..try sending alf_ticket as an attribute of params.

Resources