validate upload element for presence of a string stored in other element?

uktran

Member
Is it it possible to validate an form where one field is LIKE another?

I have a form with a field {code} and an upload element with a local filepath.

I'd like the form to validate the presence of {code} within the filepath.
 
Last edited:
Note that doing validation on the upload element is not trivial, because the form data itself won't contain a file path at the point that validations run. So you have to check PHP's $_FILES data, either directly or through J!'s input ... so in a PHP validation ...

Code:
$app = JFactory::getApplication();
$files = $app->input->files->get('yourtable___yourelement',  array(), 'raw');
$name = ArrayHelper::getValue($files, 'name', '');

That would work to get the uploaded name of a simple (non AJAX) upload element which isn't in a repeat group. If using AJAX or repeat groups, the format of the file data would be different.

You can then do whatever you need with checks on $name.

-- hugh
 
I can't get this to work sadly. So for now, I'm trying to perform check after form submission using a php list plugin to update a field if string is found in the path.

But I can't figure out how to use LIKE with placeholders. (Sorry if this is too non fabriky a question... but it works in sql, i just can't get it to work with placeholders)

Here is the code with the query in bold. The query works if you swap the placeholder for the actual string.


$ids = array_unique(JRequest::getVar('ids', array(), 'method', 'array'));
$db =& $model->getDb();
foreach ($ids as &$id) {
$id = $db->Quote($id);
}
$ids = implode(',', $ids);
$user = JFactory::getUser();
$userid = $user->get('id');
$table =& $model->getTable();
$db_table_name = $table->db_table_name;
$dbk = $table->db_primary_key;
$db->setQuery("

UPDATE $db_table_name
SET status = 'URLOK'
WHERE
urlpath like '%{table___string}%'
AND $dbk IN ($ids)


");
$db->query();
 
Thanks a lot.

Just one more thing and I think I'll be set. It works with an =, but I'm having a bit of trouble escaping the variable with a LIKE.

I've played around with different commas but no luck.

->where(' urlpath like "%' . $myDb->quote($string) . '%"
and
id = ' . $myDb->quote($id));
 
Is it working without db->quote (for testing only)?

May be do
$qstring = $myDb->quote('"%' . $string. '%"') ;
...like ' . $qstring . '
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top