Jump to content

Send with jQuery and validate with PHP


waldette

Recommended Posts

Hello all.

 

I have a problem with my module. I do a form with only one input where the client put the phone number.

 

I need to validate this phone with a external bussiness API, so return TRUE if it's correct and registered. If this number it's correct the form change asking for a PIN number sended to the phone.

 

How can i do it? How can i send the phone with jQuery and receibe TRUE or FALSE for show the new form or not?

 

I dont know if i explain it right.. :S

 

Thanks!

Link to comment
Share on other sites

what kind of api you've got? im asking because it is necessary question in this case.

how you want to call to the external scripts?

it is based on REST? json? please give more information and I will try to help :)

Link to comment
Share on other sites

Is a bussiness that send you a message to mobile if you have points for apply a discount with them. I dont analize this API yet, but i know that return TRUE or FALSE when you call the function.

 

Example:

 

$client = new SoapClient(NULL, array('uri' => self::$URL_API, 'location' => self::$URL_API.'/api/index.php'));  
$salida=$client->oo_request_pincode($_POST['connect_ole'], $_POST['nMobil'], $cart->getOrderTotal(true, Cart::BOTH));

 

this method return TRUE if its OK and then i can proceed with the next form, where the client put the PIN code sended to phone.

 

Ah, i have a form like this:

 

$(".button").click(function() {
var phone = $("input#phone").val();
$.ajax({
  type: "POST",
  url: "modules/olepoints/bin/process.php",
  data: phone,
  success: function() {
...

Edited by waldette (see edit history)
Link to comment
Share on other sites

hello

 

sorry for late reply i was offline, now im back

 

so you press the 'button' then the code do the AJAX call to the modules/olepoints/bin/process.php file.

PHP script that you've got returns false / true. If return value is "true" - create a simple echo "1"; if "false" - echo "0";

 

then in the javascript you have access to the "echo" value, for example via "data" variable:

success: function(data) {
alert(data);
}

 

now you can check the data value:

if data == 1 - make another AJAX call to script

if data == 0 - false

Link to comment
Share on other sites

wooow, its so easy!! ^^

 

Only one question, the "data" take this name or need assign one depends on anything?

 

I dont know if i explain right. Mmmmm.... if i have data: phone, dont affect to this function(data)... right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...