auto select credit card type - php

i am building payment form
and want auto select credit card type with the 1st 4 digits
i have the valid ranges on Visa Master AMEX Discover
here an example of Discover one
validRanges":["6282","6283","6284","6285","67","66","6287","6286","6288","64","65","63888","6011","622","624","625","626"]
how may i build input that auto select discover card and appear the discover icon
and disapper other ones
somethink like this
https://www.panic.com/coda/buy.html

You are surely going to need Javascript for that kind of effect. And assuming you are storing that data on the server (possibly in the database) you'll need AJAX to query the database and find out if the inputted digits are part of any range in the database.
For the Javascript part I suggest you to take a look at jQuery: specifically jQuery.ajax() and the function .fadeTo().
The basic idea you are going to implement is basically the following:
Detect any user digit input
Take the <input> input and send it (via AJAX) to a PHP script x.php
x.php processes the inputted data (possibly sent via POST method) and queries the database returning a JSON array of card types to the client side
The client side convert the JSON string to actual JSON objects and use it to hide or show specific divs representing the cards.

Related

How can I render intermediate content in Yii2?

My Yii2 based application has a process where I need to fetch data from an external SOAP API and display the results after processing. I wish to display some static data and a placeholder for results until the background process of API data fetch and processing is completed.
Is there a way to display intermediate data in Yii2 views without using Ajax? Ajax is not a suitable option in this case due to amount of data which needs to be exchanged with API, and processed before rendering the results. Plus, results format is variable, and hence different templates may need to be applied before rendering them.
EDIT: to give a clearer picture, the flow is as below:
User Submits data (UD)
Data is processed onto the server resulting in information (SI) and data (SD)
SD is submitting to external SOAP API which returns information (AI)
User shall be given the two pieces of information SI and AI, however user shouldn't be able to see the data SD at any point
Server side processing takes about 1 second, however API data interchange takes about 15 seconds
So, SI is available at t=1 sec, but AI is only available after t=16 secs. The purpose here is to not make the user wait for AI availability, and give them time to consume SI, while AI is provided when it becomes available.

Qualtrics 3rd Party Add-On Best Practices

I am working with Qualtrics, which is just a web-based survey engine. The request is that, once users finish the survey, they will receive a small prize in the form of a gift code. Since I can't host the prize code data on the Qualtrics platform, my idea was to store the prize codes on a remote server. When the user finishes the survey they will be directed to my server (https), to a PHP script that will give out the prizes. On the surface this is possible, because as one piece of customization they allow to re-direct to a URL upon completion of the survey.
The problems that I am faced with, regarding my PHP script that gives out the prizes are as follows:
1) Make sure visitors have COME FROM the survey and have actually
finished the survey.
2) Only give out 1 prize per participant per survey.
It is difficult to address #1 because it seems like after the survey is complete, you just get a basic re-direct to my site. It would be possible to add GET data to the URL, its very easily readable and doesn't offer security. Even encrypting the GET data doesn't seem feasible because a hacker could just copy the data string once they see it.
The idea I had to address #2 was to check the user's IP address using PHP, and store the address in my DB after a 1-way encryption. This way the IP would be unknown, but I could check for duplicates, only allowing 1 prize per IP.
So the question is, is it even possible to do what I am trying to do with just a simple URL re-direct? Is my idea for addressing #2 acceptable?
Thanks.
There are probably many ways this could be handled. Two that come to mind:
1) At the end of survey, Qualtrics creates an embedded data field called ResponseID which is in the Qualtrics data. You can include the ResponseID in the redirect then have your php script call the Qualtrics REST API, and try to retrieve the response with that ResponseID to make sure it exists.
2) Just before the end of survey, you could do a web service call to a script that creates a unique id, store the id on the server side, and return it to the survey as an embedded data field. Then pass the unique id in your redirect and make sure it matches a unique id you stored.
EDIT based on comment below:
You can add custom parameters to your redirect by piping in parameter values like this:
http://mywebsite.com/myscript.php?rid=${e://Field/ResponseID}
If you are able generate special request parameter for redirect url and make it for every user unique, then you could invent some algorithm, and encrypt user ID with it and pass this ID as parameter in redirect url.

Transfer Form Responses to Another Form

So what I am trying to accomplish is this; I have people cold-calling potential customers. When the caller gets a potential client on the phone and has them interested, they transfer the client to a sales agent to seal the deal.
During the initial conversation, the cold-caller collects some info in a form I have online such as name, phone number, address, etc. I need the cold caller to be able to transfer those values to the sales agent when they pass the phone call over.
The cold-caller and the sales agent are in two different buildings across town from each other, and the sales agent uses an online form to collect data as well. Capturing the values is not the problem, it is the pass from one agent to another that I cannot figure out.
I thought maybe the cold-caller could post the form to a Google spreadsheet, but I do not know how to get those values to populate on the second form when the call is passed. I need the transfer to happen within a few seconds, so sending a URL with the captured values in an email won't work due to email being unreliable in the speed department.
Anyone have any thoughts on this? I can use HTML, jQuery, or whatever. I would need help if it has to be done in AJAX....
Thanks!
Ok.
This is customer side:
Customer put data into form, send this data to server.
Server must save this data for agent.
This is agent side:
Browser send check requests (maybe automatically, maybe agent need click some button) for new data from customers.
If exists new data you should place this data into form on agent page.
$('#first-form').submit(function() {
$.post('/another-destination', $(this).serialize(), function(r) {
alert('Data sended to another destination!');
});
return true;
});
Looks like you are wanting to use HTML5 and Javascript WebSockets to be able to push data from one browser to another.
Ajax requires polling, meaning a query has to ask the server for new information.
This can be accomplished by saving and comparing the last updated timestamps from a session variable.
Websockets push data to a connected peer when it is updated allowing for data to automatically populate as it is submitted, much like a real-time chat system.
If you are stuck on PHP you should take a look at Ratchet since it is fairly straightforward and minimalistic to implement in comparison to many of the alternatives.
http://socketo.me/
Chat demo using ratchet http://socketo.me/demo
Add in a RDBMS to create, read, and update the data and you have a powerful real-time application.

php form submit counter

So I've made an extremely simple 4 page static webpage for this client with a quick contact form handled by php. Everything goes swimmingly.
Then the client comes to me and requests that he is able to see a counter of how many submits have been made. So he generally wants a counter for his form, Which is simple enough because I just add a counter for every successful email sent using the form and save it within some kind of data storage.
BUT...
the only way I can think to do it is have a separate user page with a simple box that has the number in it, that only the client can access.
I could do this... Save the counter in an xml file or a one table, one column, one row mySQL database.
But is there a better easier simpler way to do this??? Can I set up a link with Google analytics or something? Rather than making a single page with a number on it.
I suggest going with a separate page for the client to view counts. You can use .htaccess to control the access to this page. The main reason is looking forward to future client requests. Most likely, they will then ask you to show counts for specified periods of time, counts per day/week/months, etc. If you set up your page now, then you can have place to customize/extend.
As for storing the counter, I would suggest storing more than just the total. Have a table where you'd store:
date/time of form submission
remote IP address (for possible future reference)
content of the submitted form (if the client ever decides to want to see it)
maybe event content of the email (if the client ever decides to want to resend it)
Then to display the totals, you'd just select count(1) from that_table with any required date/etc. grouping.

Is it possible to fill in an Ajax form programatically using php?

I am using php to fill up a form. Now, it so happens that form is using ajax for many of its fields.
e.g.
select [country]
(ajax will show drop-down filled with states for that country)
select [states]
(ajax will show drop-down filled with cities)
select [city]
(ajax will enable a submit button)
If it is a simple html based form, it can be easily filled with cURL. But what if the form is using ajax to populate the drop-down fields.
Thanks
When you are "populating" the form with curl, you are actually POSTing the data that would have been typed/entered into the form.
There is no need for the Ajax requests to be made, as long as you know what data you have to use.
So, the solution would be to :
Begin by getting the lists of data (by using the form in a browser, for instance)
Know how those data have to be used (by observing the "normal" way the form works)
POSTing the correct values, with your curl request.
In the end, your curl request should be the same than the one made by the browser when the form is submitted -- independantly of the Ajax requests that are sent before (those are only useful for getting data)
Well, that is unless the Ajax requests are actually "writting" something on the server -- but that's pretty rare for this kind of situation.
If it is a simple html based form, it can be easily filled with cURL
I'm not clear what you mean here. As far as I know, cURL is a tool for making HTTP requests. It can't "fill forms" (unlike, for example, WWW::Mechanize). Am I wrong about this?
I think you mean: "If it is a simple HTML based form, I can easily construct an HTTP request using cURL that submits the same query string or POST data as using a browser would." I'm going to proceed on that assumption.
The use of Ajax (in of itself) doesn't stop you constructing a the form data manually and submitting it as normal. It just makes it a little more difficult to work out what data you need to submit.
The remote system might be implemented in such a way that it falls over if you don't request all the bits of data in the right sequence (e.g. it will barf if you submit the complete data at the end without requesting the list of cities for a country). Emphasis on 'might', this wouldn't be a sane way to implement the system.
You might also want to make multiple requests with cURL anyway so that you can fetch the list of cities (and any ids that might be associated with them) and access them programatically.

Categories