Podio - Embed Field - Empty string issue - podio

Has anyone had any problems saving values to embed fields with the Podio PHP API?
I keep getting the following error, although I know my array has values:
Fatal error: Uncaught PodioBadRequestError: "Invalid value ""
(string): must be non empty string" See bold code below for field
returning empty.
I have also tried using the associative array, but get the error 'must use embed or url'. http://podio.github.io/podio-php/fields/#linkembed-field
$userItem->fields[$field->external_id] = new PodioEmbedItemField();
if (is_array($_POST[$embedName])) {
$embedArray = array();
$embedValues = $_POST[$embedName];
if (isset($embedValues) && !empty($embedValues)) {
for ($i = 0; $i < count($embedValues); $i++) {
$embedObject = PodioEmbed::create(array('url' => **$embedValues[$i]**));
array_push($embedArray, $embedObject);
}
$userItem->fields[$field->external_id]->values = new PodioCollection($embedArray);
}
}

OK problem is that PodioEmbed object cannot accept array iteration, you have to assign to a variable as string first and then pass into function.
$embedString = $embedValues[$i];
$embedObject = PodioEmbed::create(array('url' => $embedString));

Related

Invalid parameter number when using whereNotIn in laravel

I want to print the list of option from database on my blade, which I want to get all list except the option that already selected. So what I've already do is getting the selected option (which is saved on another table) as an array:
$ctg_id[] = [];
foreach($vendor->category as $item){
$ctg_id[] = [$item->category_id];
}
Then finally print it:
$category = ItemCategory::whereNotIn('id',$ctg_id)->get();
But it return an error that says:
"SQLSTATE[HY093]: Invalid parameter number (SQL: select * from category_item where id not in (4, 3, ?))" Is there anything wrong with my code?
You are using double dimensional array, you need to change it to one dimensional:
$ctg_id = [];
foreach($vendor->category as $item){
$ctg_id[] = $item->category_id;
}
Recommend to use method-pluck like this:
$category = ItemCategory::whereNotIn('id', $vendor->category->pluck('category_id'))->get();

Trying to setState using eval() function (React Native)

I'm trying to set multiple states in a for loop to be false or true depending on whether they meet the (if statement) requirement. The for loop will loop through an array of strings, each string represents a state. But I can't seem to use eval within this.setState function...
I have tried researching online but none of the solutions match my problem or what I'm trying to solve. I even tried eval(this.state.anything) = false but it still doesn't work and shows a left hand assign invalid error.
let businessState = [
"this.state.groupName",
"this.state.groupOwnerName",
"this.state.groupDesc",
"this.props.profile._id",
"this.state.businessName",
"this.state.businessDesc",
"this.state.businessRegNo",
"this.state.businessType",
"this.state.businessEmail",
"this.state.businessTel",
"this.state.businessWeChat",
"this.state.businessRegPhotoUri",
"this.state.businessSignPhotoUri"
];
var temp = ""
for (i = 0; i < businessState.length; i++) {
if (eval(businessState[i]) == ""){
temp = businessState[i]+ "Error"
this.setState({
eval(temp): true
})
}
}
As you can see from the code above, I want to evaluate the state, and if the value that this particular state holds is an empty string "", I want to set this state name + "Error" (For example, if this.state.email is empty string "" I want to set this.state.emailError to true.
Instead of this.setState({eval(temp): true}) try this.setState({[temp]: true}). The brackets will output the string value stored in temp as a variable name in setState.
This article gives a good explanation
This Stack Overflow question and the accepted answer also should help

PHP7 produce error when array push is used on a string

How can I configure PHP 7 to produce an error when an item is pushed to a string, for example:
$items = '';
$items[] = 'test';
Is this possible?
In PHP 5.6 and 7.0, it is valid to convert a variable containing an empty string into an array like this. Therefore, you will need to provide your own validation to produce an exception.
function checkAndAssign($var, $val){
if (is_string($var)){
throw new ErrorException('Do not assign array item to a string');
}
return $val;
}
$items = '';
try{
$items[] = checkAndAssign($items, 'test');
}catch(Exception $e){
echo $e->getMessage();
return;
}
var_dump($items);
Results in:
Do not assign array item to a string
In PHP 7.1 this generates a Fatal Error. There is already a good answer to the question How do I catch a PHP Fatal Error if you want to attempt that.

How to clear a date from input type="date" with WebdriverIO

I'm now using WebdriverIO and developing a web app.
these days I tried to set a date from input type="date", I got errors
invalid element state: Element must be user-editable in order to clear
it.
and found that
I could get rid of the errors by using addValue() but still the value won't be cleared by any API.
client.clearElement('#deadline')
Also get
invalid element state: Element must be user-editable in order to clear
it.
How can I remove the value from the form?
You can run in browser script to clear it
browser.execute(function () {
document.querySelector('#deadline').value = '';
}, null);
OR give it some value
var date = '2020-03-28';
browser.execute(function (date) {
document.querySelector('#deadline').value = date';
}, date);
reference: https://github.com/webdriverio/webdriverio/issues/386
A more elegant way is to create a custom command and put this piece of code inside
this one worked for me:
client.selectorExecute("#dateInput", function(inputs, value) {
// you can run over the inputs
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'date') // any condition
inputs[i].value = "1973-12-09";
}
// or just do that:
inputs[i].value = "1973-12-09";
return;
})

Invalid parameter number: number of bound variables does not match number of tokens PDO insert

function mysql_insert($data_array){
$sql = "insert into `". $this->table_name. '`';
$array_keys = array_keys($data_array);
$array_keys_comma = implode(",\n", preg_replace('/^(.*?)$/', "`$1`", $array_keys));
for($a=0,$b=count($data_array); $a<$b; $a++){ $question_marks .="?,"; }
$array_values = array_values($data_array);
$array_values_comma = implode(",", $array_values);
$sql.= " ($array_keys_comma) ";
$sql.= " values(". substr($question_marks, 0,-1) .")";
$prepare = $this->connDB->prepare($sql);
$insert = $prepare->execute(array($array_values_comma));
}
I want to creat like this universal functions, $data_array-comes from $_POST
This function will work for all form. But i dont know what is my wrong :S
I don't know what is my wrong
That's quite easy to know: number of bound variables does not match number of tokens.
I want to creat like this universal functions, $data_array-comes from $_POST
Here you go: Insert/update helper function using PDO
$array_values_comma is a scalar after you implode() the array. So you always pass an array of one element to your execute() function. You should pass $array_values.
Here's how I'd write this function:
function mysql_insert($data_array){
$columns = array_keys($data_array);
$column_list_delimited = implode(",",
array_map(function ($name) { return "`$name`"; }, $columns));
$question_marks = implode(",", array_fill(1, count($data_array), "?"));
$sql = "insert into `{$this->table_name}` ($column_list_delimited)
values ($question_marks)";
// always check for these functions returning FALSE, which indicates an error
// or alternatively set the PDO attribute to use exceptions
$prepare = $this->connDB->prepare($sql);
if ($prepare === false) {
trigger_error(print_r($this->connDB->errorInfo(),true), E_USER_ERROR);
}
$insert = $prepare->execute(array_values($data_array));
if ($insert === false) {
trigger_error(print_r($prepare->errorInfo(),true), E_USER_ERROR);
}
}
A further improvement would be to do some validation of $this->table_name and the keys of $data_array so you know they match an existing table and its columns.
See my answer to escaping column name with PDO for an example of validating column names.