TOPIC:

How to show a warning if a value is repe 1 month 1 week ago #281930

  • Topic Author
  • arancha21
  • Offline
  • Junior Member
  • Junior Member
  • Registered
  • Posts: 65
  • Thanks: 0
Hello,
I am designing a form in which one of the fields is name and surname. I would like to know how I can make it so that the form cannot be filled in if the name and surname value is already registered in a previous form and the value appears in the database.
Thanks for your help.

Please Log in or Create an account to join the conversation.

How to show a warning if a value is repe 1 month 3 days ago #282075

  • Topic Author
  • arancha21
  • Offline
  • Junior Member
  • Junior Member
  • Registered
  • Posts: 65
  • Thanks: 0
Hello,
I do not receive answers to my queries. Perhaps it is that these queries cannot be made to this forum?

Please Log in or Create an account to join the conversation.

How to show a warning if a value is repe 1 month 2 days ago #282135

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Administrator
  • Administrator
  • Super Users
  • Posts: 10544
  • Thanks: 859
Hi, sure, no worries. I am just doing a large update for ContentBuilder and I am therefore much slower as I should. Sorry for that.

I attached you a completely working form that showcases how it works. You can build upon it it. Make sure to download, unzip and install in BF => Configuration => Package Installer.

The trick is basically having a custom validation on the firstname (could also be just the lastname) that calls the form for checks on the database state:
function ff_firstname_validation(element, message)
{
  
  JQuery.ajaxSetup({
    async: false
   });
  let result = null;
  
  JQuery.getJSON( '<?php return JUri::root(true)?>/index.php?option=com_breezingforms&ff_form=<?php return intval($_REQUEST["ff_form"]) ?>&checkAjax=1&firstname='+encodeURIComponent(ff_getElementByName('firstname').value) + '&lastname='+encodeURIComponent(ff_getElementByName('lastname').value), function( data ) {
     
                 result = data;
                 
  });

  
  return result === true ? message : '';
}

Then in form => advanced => more options => form pieces => before form => there is the actual server-side code that returns the state of the database to the calling validation above:
if(isset($_REQUEST['checkAjax']) && $_REQUEST['checkAjax'] == '1' && isset($_REQUEST['firstname']) && isset($_REQUEST['lastname'])){

	$handlers = ob_list_handlers();
    while (count($handlers) > 0 && $handlers[count($handlers) - 1] != 'ob_gzhandler' && $handlers[count($handlers) - 1] != 'zlib output compression') {
        ob_end_clean();
        $handlers = ob_list_handlers();
    }

	header("Content-Type: application/json");

	$records = array();
	$db = BFFactory::getDbo();
	$db->setQuery("Select * From #__facileforms_elements Where form = " . $db->quote(intval($_REQUEST['ff_form'])));

	$rows = $db->loadObjectList();
	$cnt = count($rows);

	for($i = 0; $i < $cnt; $i++)
	{
		$db->setQuery("Select * From #__facileforms_subrecords Where name = 'firstname' And value = " . $db->quote($_REQUEST['firstname']));
      
      	$sub = $db->loadObject();
      	
      	if($sub)
      	{
      		$db->setQuery("Select * From #__facileforms_subrecords Where name = 'lastname' And value = " . $db->quote($_REQUEST['lastname']));
      
      		$sub2 = $db->loadObject();
      
      		if($sub2)
      		{
      			echo 'true';
      			exit;
      		}
    	}
	}
      
    echo 'false';
    exit;
}

Since this is tested on Joomla4, please replace "BFFactory" above with "JFactory" if you run this on Joomla3 after installation of the form.

This way everything is nicely self-contained and can be adjusted for custom needs.

File Attachment:

File Name: FirstLastOnlyOnce.zip
File Size:8 KB


Regards,
Markus
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.

How to show a warning if a value is repe 1 month 2 days ago #282153

  • Topic Author
  • arancha21
  • Offline
  • Junior Member
  • Junior Member
  • Registered
  • Posts: 65
  • Thanks: 0
Thank you very much for your help!
I see that this solution generates a new form of type "search" that allows me to find if a value already appears in the database. What I was looking for is that from the same form (and not from a new one) an error message can be displayed if the name value (for example) that is written is already registered in a previous form. Could it be that the solution is that from the element itself, in the Validation part, I can adapt this code by selecting Custom? I capture screen.

I imagine that you are very busy with the adaptation of Content Builder (this application is wonderful!), I will understand if you cannot answer me of course.

Thank you very much again.
Attachments:

Please Log in or Create an account to join the conversation.

How to show a warning if a value is repe 1 week 3 days ago #282422

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Administrator
  • Administrator
  • Super Users
  • Posts: 10544
  • Thanks: 859
Hi,

I believe my solution does exactly what you were originally asking for. If you need adjustments, please let me know after you tested it.

Regards,
Markus

Please Log in or Create an account to join the conversation.

How to show a warning if a value is repe 1 week 3 days ago #282423

  • Topic Author
  • arancha21
  • Offline
  • Junior Member
  • Junior Member
  • Registered
  • Posts: 65
  • Thanks: 0
Hello,
I have already tried it in several forms but I can't get it to work. Thanks for your interest.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Time to create page: 0.060 seconds

Support Chat

Join our Discord chat and enter the Crosstec channels for live-support, chat forums and interact directly with the community!

After joining, please enter the Crosstec Area and use the #crosstec-support or #crosstec-general channels.

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Subscribe to news and updates!

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here and enter the Crosstec channels to receive live support and talk directly to the team!