check before saving and show entries

Status
Not open for further replies.

susannanam

Member
hi all,

i want to realize the following:
when filling out a form with data and clicking on the save button, a routine shall first run (existing sql function) to check, if similar entries are available. those entries shall now be shown in a popup screen or so. either the user can now select to open an existing one (and therefore NOT save his entries) or he can say that none of the existing ones is correct and decide to finally save his entries in the database or he can simply cancel the whole procedure and neither save his entries, nor open an existing one.

what would be the easiest/best way to do that? thanks for any hint :)
susanne
 
HI Susannanam,

I have had to do the SAME exact thing for a form of mine. I had to check if existing data existed. If existing data exists already, form does not submit, and redirects to that record on edit mode.

Of course, the code would be MUCH simpler than my version, because I'm checking for a lot more complex matches.

Start with creating a php file under plugins/fabrik_form/php/scripts then in your form in the backend, you can select the custom php file.
Code:
function doLayupExists() {
    $app = JFactory::getApplication();
    $input = $app->input;
    $brand_id = $input->get('tblfoo_sp___brand_id', '', 'array');
    $brand_id = $brand_id[0];
   
    $sps = array();
    for ($sp = 1; $sp <= 34; $sp++) {
        $sp_val = $input->get('tblfoo_sp___sp' . $sp, '', 'array');
        $sp_val = is_array($sp_val) ? $sp_val[0] : $sp_val;
        if (empty($sp_val)) {
            $sp_val = "(sp" . $sp . " = '[\"\"]' OR sp" . $sp . " = '')";
        }
        else {
            $sp_val = "sp" . $sp . " = '[\"1\"]'";
        }
        $sps[$sp] = $sp_val;
    }
    $sp_where = implode(' AND ', $sps);
    $sp_where .= " AND brand_id = " . $brand_id;
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select('*')->from('tblfoo_sp')->where($sp_where);
   
   
   
    //echo $query;exit;
    //var_dump($sps, $sp_where);exit;
    $db->setQuery($query);
    $row = $db->loadObject();
    if (!empty($row)) {
        $app->enqueueMessage('Dumbass, this one exists');
        $app->redirect("/route/toyour/page/form/73/" . $row->id);
    }
    else {
        $app->enqueueMessage("Query: " . (string)$query);
    }
}


Hope this helps!
 
HI Susannanam,

I have had to do the SAME exact thing for a form of mine. I had to check if existing data existed. If existing data exists already, form does not submit, and redirects to that record on edit mode.

Of course, the code would be MUCH simpler than my version, because I'm checking for a lot more complex matches.

Start with creating a php file under plugins/fabrik_form/php/scripts then in your form in the backend, you can select the custom php file.
Code:
function doLayupExists() {
    $app = JFactory::getApplication();
    $input = $app->input;
    $brand_id = $input->get('tblfoo_sp___brand_id', '', 'array');
    $brand_id = $brand_id[0];
 
    $sps = array();
    for ($sp = 1; $sp <= 34; $sp++) {
        $sp_val = $input->get('tblfoo_sp___sp' . $sp, '', 'array');
        $sp_val = is_array($sp_val) ? $sp_val[0] : $sp_val;
        if (empty($sp_val)) {
            $sp_val = "(sp" . $sp . " = '[\"\"]' OR sp" . $sp . " = '')";
        }
        else {
            $sp_val = "sp" . $sp . " = '[\"1\"]'";
        }
        $sps[$sp] = $sp_val;
    }
    $sp_where = implode(' AND ', $sps);
    $sp_where .= " AND brand_id = " . $brand_id;
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select('*')->from('tblfoo_sp')->where($sp_where);
 
 
 
    //echo $query;exit;
    //var_dump($sps, $sp_where);exit;
    $db->setQuery($query);
    $row = $db->loadObject();
    if (!empty($row)) {
        $app->enqueueMessage('Dumbass, this one exists');
        $app->redirect("/route/toyour/page/form/73/" . $row->id);
    }
    else {
        $app->enqueueMessage("Query: " . (string)$query);
    }
}


Hope this helps!

hi Tessa,

thanks so much for your answer :) since the "existing" records will be more than one, i need to list them and the user can select if and which one he would like to open. how could i implement that into your routine?

thanks
susanne
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top