This topic is locked

Pop Up if fields are empty

4/20/2012 7:22:20 AM
PHPRunner General questions
buddy author

I have a database containing the following fields:
Field1

Field2

Field3
these are text fields where selections are made by radio buttons. What I need to do is:
before the record is added, check whether these fields have any value.
If any of them do, add the record

If there were no selections in these fields, then show a popup "You must enter a value in at least one field". and not allow the page to be added until the user makes a selections.
Can't seem to figure it out.
Any help is appreciated.

W
wildwally 4/20/2012



I have a database containing the following fields:
Field1

Field2

Field3
these are text fields where selections are made by radio buttons. What I need to do is:
before the record is added, check whether these fields have any value.
If any of them do, add the record

If there were no selections in these fields, then show a popup "You must enter a value in at least one field". and not allow the page to be added until the user makes a selections.
Can't seem to figure it out.
Any help is appreciated.


I think I can offer you some assistance with this. Couple different ways you could go about doing this. One make them required in the editor, then they highlight Red indicating where the field is on the page that still requires a value. This is most likely the simplest solution for you to take.
An alternate method would be to code a if statement into the Before record added event section for the page. Something along the lines of this:


IF(!$values['Field1'])

{

print "<script type=\"text/javascript\">\n";

print "window.alert(\"field1 is blank\")\n";

print "</script>";

return false;

}
buddy author 4/21/2012



I think I can offer you some assistance with this. Couple different ways you could go about doing this. One make them required in the editor, then they highlight Red indicating where the field is on the page that still requires a value. This is most likely the simplest solution for you to take.
An alternate method would be to code a if statement into the Before record added event section for the page. Something along the lines of this:


IF(!$values['Field1'])

{

print "<script type=\"text/javascript\">\n";

print "window.alert(\"field1 is blank\")\n";

print "</script>";

return false;

}



Perfect. Thanks

C
cgphp 4/22/2012

You can directly make a validation check in the "Javascript onload" event, so the popup doesn't close after you have clicked the "Save" button:

var ctrl1 = Runner.getControl(pageid,'radio_name_1');

var ctrl2 = Runner.getControl(pageid,'radio_name_2');

var ctrl3 = Runner.getControl(pageid,'radio_name_3');
this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

if(ctrl1.getValue() == '' && ctrl2.getValue() == '' && ctrl3.getValue() == '')

{

alert("You must enter a value in at least one field");

return false;

}

});