My post data is from Captcha adapter is as following:
["ffck"] => array(2) {
["id"] => string(32) "661db3996f5e60e71a60671496ec71a9"
["input"] => string(3) "dys"
}
My code is trying to validate now, but always failing:
Zend_Loader::loadClass('Zend_Captcha_Image');
$captcha = new Zend_Captcha_Image();
$captchaArray = array(
'id' => $post['ffck']['id'], // valid id
'input' => $post['ffck']['input'] // valid input
);
if ($captcha->isValid($captchaArray)) { // FAILs!!!!
echo "working";
} else {
echo "fails";
}
Zend_Debug::dump($post) ; // 100% valid ....
exit;
How to fix it? Or whats causing this to fail?
Check the generated html, you should only have two inputs: name="captcha[id]" and name="captcha[input]", if you have a third one with name="captcha", then you have to remove the viewhelper from the captcha element before rendering.
Ex.:
$form->getElement('captcha')->removeDecorator("viewhelper");
The array you pass to the CAPTCHA object should just contain the two keys, so try:
$captchaArray = $post['ffck']
instead of what you are currently doing.
But the code you've posted is not valid anyway since you never generate the CAPTCHA image. I imagine you've cut down the code sample to keep the question short, so if the above fix doesn't work please edit your example to include how and where the CAPTCHA image is generated.
Related
I want to save xml document in mysql database as below:
$_docId= $this->getRequest()->getParam('docId', 0);
$_slmData = '<SLM_form_v2 id="slmform"><group_1_1><section1_1/><name1_1>sdfds</name1_1>
enter code here<localname1_2/><selectcountry_1_3>Algeria</selectcountry_1_3></group_1_1>
enter code here<group_1_2><main_doc/><name_doc1>gdgf gfh f</name_doc1><sex_doc1>Male
</sex_doc1><name_institution_1>fsdgdfg</name_institution_1><address_institution_1>gdgfdgfd
</address_institution_1>....';
$_docMapper = new Model_Mapper_XMLDoc();
$_docModel = new Model_XMLDoc();
$_docModel ->doc_data = Zend_Json::encode($_docData);
if ($_docId != 0) {
$_docModel->id = $_docId;
$_docMapper->update($_docModel->toArray(), 'id = ' . $_docId);
$_action = 'update';
} else {
$_docMapper->insert($_docModel->toArray());
$_lastId = $_docMapper->getAdapter()->lastInsertId(); //gets the id of the last inserted record
$_action = 'add';
}
$this->_helper->json->sendJson(array(
'message' => 'success',
'id' => $_lastId,
'action' => $_action
));
It is stored in the db:
INSERT INTO crpcoreix.tbl_xml_doc (slm_data, web_gis_fk) VALUES ('"<SLM_form_v2 id=\\"slmform\\"><group_1_1><section1_1\\/><name1_1>sdfds<\\/name1_1><localname1_2\\/><selectcountry_1_3>Algeria<\\/selectcountry_1_3><\\/group_1_1><group_1_2><main_doc\\/><name_doc1>gdgf gfh f<\\/name_doc1><sex_doc1>Male<\\/sex_doc1><name_institution_1>fsdgdfg<\\/name_institution_1><address_institution_1>gdgfdgfd gdgf<\\/address_institution_1>...', null);
When I'm trying to read the data from the database and display the encoded xml tags the output miss the first part ("<SLM_form_v2 id=\\"slmform\\"><group_1_1><section1_1\\/><name1_1>...) the first part
Array
(
[id] => 1
[xml_data] => "sdfds<\/name1_1>Algeria<\/selectcountry_1_3>...'
[web_gis_fk] =>
)
Please advice how to fix and if there is a better way to store xml documents in database.
Thanx,
first is first you need to double check your given xml syntax, whether its correct or not.
Zend_Json includes a static function called Zend_Json::fromXml(). so
you would better manage to use it instead of Zend_Json::encode when
you encode XML
This function will generate JSON from a given XML input.
This function takes any arbitrary XML string as an input parameter. It also takes an optional Boolean input parameter to instruct the conversion logic to ignore or not ignore the XML attributes during the conversion process.
If this optional input parameter is not given, then the default behavior is to ignore the XML attributes. This function call is made as shown below:
$jsonContents = Zend_Json::fromXml($xmlStringContents, true);
Give it a try but again check your XML syntax
I update an existing document with the code below. Its working fine.
foreach($jArray as $value){
!!some code!!
try {
$collection->update(array("tablename"=>$tablename),array('$push' => array("inventar" => $new_data)));
echo json_encode($collection);
}
catch ( MongoConnectionException $e ) {
echo '<p>Update failed</p>';
exit();
}
}
JSON response:
{"w":1,"wtimeout":10000}{"w":1,"wtimeout":10000}
(2 values are tried to update)
Even if no tablename matched, means no update happend, the result is w = 1.
Why? No update happend and w is 1/true?
There seems to be a little confusion here. The JSON response you are looking at is not the actual return value from the update operation. What you did was JSONifying the collection itself, which has the integer attributes w and wtimeout (see source code here). Those attributes are in no way related to the result of the update operation itself.
So, the right way to go seems to be changing the lines inside the scope of your try statement to:
$result = $collection->update(array("tablename"=>$tablename),array('$push' => array("inventar" => $new_data)));
echo json_encode($result);
For more information about what is returned from the update method, refer to these docs.
I am using Kohana's validation methods to ascertain that certain mandatory values are present inside a form. While validating confirm_password the 'errors' method of ORM_Validation_Exception is returning array in the following format
array(1) (
"_external" => array(1) (
"password_confirm" => string(45) "password confirm must be the same as password"
)
)
How can i make it follow the same convention as rest of the errors so that i can do the following and just iterate through the errors in the view file.
$Errors = $e->errors('user'); // inside the controller
<?php if ($Errors): ?>
<p class="message">Some errors were encountered, please check the details you entered.</p>
<ul class="errors">
<?php
echo Debug::vars($Errors);
foreach ($Errors as $message): ?>
<li><?php echo $message ?></li>
<?php endforeach ?>
<?php endif;
I have tried adding an _external file under messages(also tried placing it in /messages/model) folder, but it doesn't seem working. Should I call $Errors = $e->errors('_external') to load the error messages, in that case all how can i load messages from 'User' file which contains rest of the error messages?
Even if you translate the errors using a message file (which in your case should go in messages/user/<model>/_external.php), your $Errors array will still have the same structure i.e. external error messages will be in their own sub-array, $Errors['_external'].
If you need it 'flattened' I think you'll have to do that manually, e.g.:
// The next line is from your question
$Errors = $e->errors('user'); // inside the controller
// If there are any '_external' errors, we place them directly into $Errors
if (isset($Errors['_external']))
{
// Keeps track of a possible edge case in which the _external
// array has a key '_external'
$double_external = isset($Errors['_external']['_external']);
// Move the elements of the sub-array of external errors into the main array
$Errors = array_merge_recursive($Errors, $Errors['_external']);
// Remove the '_external' subarray, except in the edge case
if (!$double_external)
{
unset($Errors['_external']);
}
}
You should merge them, as far ar I know there is no function or whatsoever in the framework which does this for you. Unfortunately.
$errors = $e->errors('user');
$errors = Arr::merge($errors, Arr::get($errors, '_external'));
unset($errors['_external']);
I am creating a 3D Secure PHP Project. I am having a rather bizzare issue in that the "MD" code is going missing when re-submitting the Array of data
My code is as follows :
$paRes = $_REQUEST['PaRes'];
$md = $_REQUEST['MD'];
require "payment_method_3d.php";
x_load('cart','crypt','order','payment','tests');
/*
* For Debugging Purposes
* Only.
echo "The Value Of PaRes is : ";
echo $paRes;
*/
$soapClient = new SoapClient("https://www.secpay.com/java-bin/services/SECCardService?wsdl");
$params = array (
'mid' => '',
'vpn_pswd' => '',
'trans_id' => 'TRAN0095', // Transaction ID MUST match what was sent in payment_cc_new file
'md' => $md,
'paRes' => $paRes,
'options' => ''
);
It seems that the $_REQUEST['MD'] string seems to go missing AFTER the soap call. Although I am having difficulty print this out to the screen. The strange thing is the $paRes variable works without issue.
Any ideas why this would be the case?
Check your case. PHP array keys are case sensitive. From this little bit of code it looks as if the request variable may be 'md' instead of 'MD'.
Try $md = $_REQUEST['md'];
PHP array statements are case sensitive, so this should work:....
$md = $_REQUEST['md'];
Thanks for your responses guys.
What was happening was the include page was sitting in front of the request methods and causing issues loading the REQUEST methods to the page.
I am using a twitter class to post updates to my account for this I have removed my twitter credentials so I am aware that XXXXX is wrong. I am able to parse the text from the remote xml file. This xml files text always reads "There are no active codes." So in my if statement i said that if the xml file reads "There are no active codes." i dont want to post anything to my twitter, but if it changes to anything else then i would like to parse that information and post it to my twitter. So today when there was an update to the xml file nothing happened. I know that the twitter portion is correct because I have a similar script that does not use an if statement and it posts fine. Once i introduced the if statement i have run into problem of not being able to post. So what can i do to post to twitter only when the xml file changes from "There are no active codes." to anything else?
// Parse Message
$source = file_get_contents('WEBSITE_URL_GOES_HERE');
$dom = new DOMDocument();
#$dom->loadHTML($source);
$xml = simplexml_import_dom($dom);
$match = $xml->xpath("//code_message");
//Twitter class (Updating status)
require_once 'twitteroauth.php';
//Twitter credentials
define("CONSUMER_KEY", "XXXXXX");
define("CONSUMER_SECRET", "XXXXXX");
define("OAUTH_TOKEN", "XXXXXX-XXXXXX");
define("OAUTH_SECRET", "XXXXXX");
// Verify credentials
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get('account/verify_credentials');
//If Statement
if ( $match[0] == "There are no active codes." ) {
/* Do Nothing */;
} else {
$connection->post('statuses/update', array('status' => 'New Code Available - ' . $match[0] ));
return $connection;
}
var_dump of the $match array:
array(1) { [0]=> object(SimpleXMLElement)#3 (1) { [0]=> string(32) "There are no active codes." } }
You should probably use a string comparison function.
like strcmp : http://php.net/manual/en/function.strcmp.php
if (strcmp($match,"There are no active codes.") != 0 )
{
$connection->post('statuses/update', array('status' => 'New Code Available - ' . $match[0] ));
return $connection;
}
Why don't you just add some debugging code and check what's going on? Echo you $match[0] and check what's in there. It's hard to imagine "if" being broken, isn't it? Maybe var_dump($match) just to check what's going on. Then you should probably either fix your condition or fix the retrieval of $match.
Check your array: the [0] element is an object, not a string. You need to get the first element of that object, if you know what I mean.
You are comparing:
Object(SimpleXMLElement)#3 (1) { [0]=> string(32) "There are no active codes." }
to
"There are no active codes."
Which is obviously not the same.
I can't test it from here, but check out the manual of simpelXMLElement: http://php.net/manual/en/class.simplexmlelement.php
You should probably get away with a simple call. Just check out what kind of object you have. A simple example would be something like "$match[0]->childname", but I can't quickly see what the childname is. Check out the manual for some sort of getchild or something, shouldn't be too tricky