Forums

onSubmit Events Code Always submits 2 records.

Leethyl 07 Jul, 2010
Hi,

I have been messing around with creating articles from the form submissions. I have managed to find a way to do this. What I simply do is link the jos_content table to my form as well as the table that stores the data of the form.

What I do is in the "onSubmit Events Code" block, I entered the following code:
<?php 

$row =& JTable::getInstance("content", "Table");

JRequest::setVar( "title", JRequest::getVar( "title", "New Form Submission", "post", "string"));
JRequest::setVar( "alias", JRequest::getVar( "alias", "new-form-submission", "post", "string"));
JRequest::setVar( "introtext", JRequest::getVar( "introtext", "This is the content", "post", "string"));
JRequest::setVar( "state", JRequest::getVar( "state", 1, "post", "int"));
JRequest::setVar( "sectionid", JRequest::getVar( "sectionid", 22, "post", "int"));
JRequest::setVar( "catid", JRequest::getVar( "catid", 61, "post", "int"));
JRequest::setVar( "created", JRequest::getVar( "created", date("Y-m-d")." - ".date("H:i:s"), "post", "string"));
JRequest::setVar( "created_by", JRequest::getVar( "created_by", 62, "post", "int"));
JRequest::setVar( "publish_up", JRequest::getVar( "publish_up", date("Y-m-d")." - ".date("H:i:s"), "post", "string"));
JRequest::setVar( "attribs", JRequest::getVar( "attribs", "show_title=\nlink_titles=\nshow_intro=\nshow_section=\nlink_section=\nshow_category=\nlink_category=\nshow_vote=\nshow_author=\nshow_create_date=\nshow_modify_date=\nshow_pdf_icon=\nshow_print_icon=\nshow_email_icon=\nlanguage=\nkeyref=\nreadmore=", "post", "string"));
JRequest::setVar( "metadata", JRequest::getVar( "metadata", "robots=\nauthor=", "post", "string"));

$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );
if (!$row->bind( $post )) {
	JError::raiseWarning(100, $row->getError());
}				
if (!$row->store()) {
	JError::raiseWarning(100, $row->getError());
}

?>

This works like a charm and creates an article for me without problems. However, it is ALWAYS creating 2 records on the table instead of 1. Is this a bug in the onSubmit event??
GreyHead 08 Jul, 2010
Hi Leethyl,

Is this a bug in the onSubmit event??

No, no bug.

My best guess is that if you have jos_content linked to your form through the DB Connection then ChronoForms is saving a copy as well as the copy you are saving.

Bob

PS The submit_content form from the downloads area here has most of this code already included.
Leethyl 08 Jul, 2010
wait, ok yes, I have jos_content linked in my db connection but that is so that I can run my extra code and insert an article. But it is getting inserted twice.
Leethyl 08 Jul, 2010
no need to worry about this anymore. 🙂

All I did was simply add this piece instead of the other binding and storing pieces:

JRequest::setVar( "title", JRequest::getVar( "title", "New Form Submission", "post", "string"));
JRequest::setVar( "alias", JRequest::getVar( "alias", "new-form-submission", "post", "string"));
JRequest::setVar( "introtext", JRequest::getVar( "introtext", "This is the content", "post", "string"));
JRequest::setVar( "state", JRequest::getVar( "state", 1, "post", "int"));
JRequest::setVar( "sectionid", JRequest::getVar( "sectionid", 22, "post", "int"));
JRequest::setVar( "catid", JRequest::getVar( "catid", 61, "post", "int"));
JRequest::setVar( "created", JRequest::getVar( "created", date("Y-m-d")." - ".date("H:i:s"), "post", "string"));
JRequest::setVar( "created_by", JRequest::getVar( "created_by", 62, "post", "int"));
JRequest::setVar( "publish_up", JRequest::getVar( "publish_up", date("Y-m-d")." - ".date("H:i:s"), "post", "string"));
JRequest::setVar( "attribs", JRequest::getVar( "attribs", "show_title=\nlink_titles=\nshow_intro=\nshow_section=\nlink_section=\nshow_category=\nlink_category=\nshow_vote=\nshow_author=\nshow_create_date=\nshow_modify_date=\nshow_pdf_icon=\nshow_print_icon=\nshow_email_icon=\nlanguage=\nkeyref=\nreadmore=", "post", "string"));
JRequest::setVar( "metadata", JRequest::getVar( "metadata", "robots=\nauthor=", "post", "string"));
This topic is locked and no more replies can be posted.