CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Updating label from OnValidate [RESOLVED]

Print topic Send  topic

Author Message
eugeneGlobal

Posts: 7
Posted: 01/10/2014, 7:26 AM

**********DISCLAIMER**********
PHP and CodeCharge n00b

Ok, so I have a form. I created an OnValidate event, in which I am running some PHP code that checks for valid dates and if everything passes the information is inserted into database.

All that functionality works fine, my problem is after the insert. I am trying to come back to my index.php page and display a message "record inserted successfully...."

I can't seem to figure out how to either change a label to display this message or echo it or set the innerHTML of a span or something. The only option I can figure out is to echo the message and exit in the OnValidate event. This obviously brings me to a blanks page with my message. I guess this is fine as I am also including a link to add a new record, but I feel like there should be a way to submit the form, process it and display a message back on the same page above the form.

Can any one provide some assistance? Thank in advance for your patience and understanding is this is a duplicate post.

Thanks,
- Eugene

View profile  Send private message
saseow

Posts: 744
Posted: 01/10/2014, 8:04 AM

Hi Eugene,
There are countless ways to do this but the following came to mind first:
Create a label on the page with the message you want to display on a successful insert and put this label into a panel.
In the after insert event of the form, create a session variable e.g.: CCSetSession("saved",1);
In the panel before show event put this:
if (CCGetSession("saved") == 1;
{
$Component->Visible = true;
}
else
{
$Component->Visible = false;
}
CCSetSession("saved",'');//Clear the variable

That should do the trick.
View profile  Send private message
eugeneGlobal

Posts: 7
Posted: 01/10/2014, 8:20 AM

@saseow

Seems logically enough, however what if I wanted to put dynamic text in the label (i.e. "User [John Doe] has been added successfully")

Also I don't think I am using the conventional insert event. I have custom PHP code to connect to DB and perform insert statement [in the OnValidate event]. Is this not recommended?

BTW my background is in ColdFusion, and I have never used CodeCharge before. I am used to hand coding everything. For Example in ColdFusion..I would create form that post back to same page. After form processing and DB insertion, I would set a variable with my success message and then before the form code I would check to see if success message is set and if it is I would display the text.

This is my though process (and ultimate goal) so you can understand when I am getting lost.

Thanks again.
View profile  Send private message
saseow

Posts: 744
Posted: 01/10/2014, 8:45 AM

For dynamic text you can get the users name from the session variable 'UserID' and look up the name in the users table and then give the label the message with Lable1->SetValue("whatever you like");.
You should really leave out custom code in the on validate event and let CCS handle the insert and it will then call the AfterInsert event where you can do the 'saved' session var stuff.
CCS does all the basic chore stuff and it does it very well. I leave nearly everything to CCS and only use custom code when I need it or CCS does not work as it should. At times I use straight PHP code for session stuff as I have come across situations where CCS bombs out.
Validation I usually put into the provided form parameters unles it is something that CCS does not have like date before/after, custom Regex etc. etc.
Give it a try. CCS does a remarkably good job with all the standard stuff you need.
View profile  Send private message
eugeneGlobal

Posts: 7
Posted: 01/10/2014, 8:54 AM

Thank you very much for your help.

I implemented your solution...leaving my code in the onValidate event and setting the session after I performed my insert statement.

As I said this is my first time using CCS. I am at a new job and they are having me work on this project. I shall ask my boss how they prefer doing things in terms of custom code vs letting CCS do the work, but I wanted to get it to a functioning state as I would have done in CF before I show him and ask for feedback and "standard" way of doing it.

Thanks again. Look forward to you help in the future :-)
View profile  Send private message
saseow

Posts: 744
Posted: 01/10/2014, 9:06 AM

You are very welcome. Just add "Resolved" to the subject. It helps others.
Good luck with the project!
View profile  Send private message
eratech


Posts: 513
Posted: 01/10/2014, 10:06 PM

Agree with saseow - CCS works best when you let it do the CRUD stuff and you fill in the custom gaps.

If you are doing custom code everytime you connect to the DB for selects and updates, then you miss out on all the speed that CCS gives you.

Eric
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.