Forums

Call to a member function setQuery() on a non-object

Becca800 25 Feb, 2009
Okay, I am trying to call the article id from the article which the form (using contentsubmit) posts. In my form, I also access the jos_menu table and inputs the preliminary information for the menu connection. The only thing I am missing is the path, which is why I need the article id.

I found that the Twitter extension has a php file which will automatically call the file and post it on twitter. I attached it. So I tried to take come of this code and add it into the form. Rough hack. I really have no idea what I am doing. I tried:

<?php 
$database =& JFactory::getDBO();
					$query = 'SELECT id FROM #__content ORDER BY id DESC LIMIT 1';
					$db->setQuery( $query );
					$rows = $db->loadObjectList();

					/*
					   Create first element of address [place on server]
					   it is IMPORTANT if site is located in subdir😉
					*/
					$SERVER = $_SERVER['SERVER_NAME'];		// www.serwer.com
					$REST_OF_SERVER = $_SERVER['REQUEST_URI'];	// /account_user/administrator/index.php
					$SUB_DIR = '';
					$tablica = explode( '/', $REST_OF_SERVER );

		    
					//Create Sub-dirs
					for($x=1; $x<=count($tablica)-1; $x++)
					{
						$indeks='';
						if( strlen($tablica{$x})>8 )
						{
							for($p=0; $p<=8; $p++)
							{
								$indeks.=$tablica{$x}[$p];
							}
						}

						if( ( $indeks == 'index.php' ) || ( $tablica{$x} == 'administrator' ) )
							$x = count($tablica)-1;
						else
							$SUB_DIR = $SUB_DIR.'/'.$tablica{$x};
					}

					$lastchar=substr($SUB_DIR, -1, 1);
					if($lastchar!='/')
						$SUB_DIR = $SUB_DIR."/";
		    

					//Create second element of address [directly location file]
					$LAST_ID = $rows[0]->id;
		    			$ARTICLE_ID = $LAST_ID+1;
					require_once( JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php' );

					$path = ContentHelperRoute::getArticleRoute( $ARTICLE_ID );

					//Create full path of article
					$address = 'http://'.$SERVER.$SUB_DIR.$path;
?>


The $path is what I need. I added the variable into the code as well and when I test out my form I get:

Fatal error: Call to a member function setQuery() on a non-object in /home/mytown5/public_html/components/com_chronocontact/chronocontact.php(421) : eval()'d code on line 32


Any thoughts? Or easier hacks?
GreyHead 25 Feb, 2009
Hi Becca800,

Which version of ChronoForms are you using?

In the latest versions this info is automatically available to you. I just tested in ChronoForms 3.1 RC2[list]
  • Use the Run Order tab in the Submit Content Form to put the AutoGenerated Code *before* the OnSubmit After Code.
  • In the OnSubmit After box add
    global $row_jos_content;
  • The article id is then at $row_jos_content->id
  • [/list]
    Bob
    Becca800 25 Feb, 2009
    I changed the run order and I added in the submit after box:

    global $row_jos_content;
    $row_jos_content->id;
    $id = $_POST['id'];


    and then
    
    $_POST['link'] = 'index.php?option=com_content&view=article&id=' . $id;


    But it did not work. The link should have still been posted without the article id in any event but it was not, I must have done something wrong...
    GreyHead 25 Feb, 2009
    Hi Becca800,

    Try:
    global $row_jos_content;
    $id = $row_jos_content->id;
    . . .
    $link = "index.php?option=com_content&view=article&id=$id";
    JRequest::setVar('link', $link, 'post');
    ?>

    Bob
    Becca800 26 Feb, 2009
    Nope. I have tried many combinations. When I changed the run order, as suggested above, nothing shows up in the link to box, not even the text portion. So I changed it back and I get the first portion of the link no article id yet.

    edit... Actually, with the run order as suggested, all of the article information does not get imputed correctly either. The body is fine, but the parameters and even the category is not posted.

    second edit: i moved the article information (all of the data submissions) to the submit before box, kept the run order as you suggested, and the article posted correctly with category, but the link in the jos_menu still will not post.
    GreyHead 26 Feb, 2009
    Hi becca800,

    OK that version will give you the article id - but what are you trying to do with it? Add it back into the article itself? Surely you don't need to do that - the article id is always available from the article parameters.

    Bob
    Becca800 26 Feb, 2009
    Hi GreyHead. My submitcontent form accesses the jos_content table and the jos_menu table. The form creates the article and dumps it into jos_content. The form creates a menu item in jos_menu to connect it to the article just created. Therefore I need the article id of the newly created article to create the "link" which is added into jos_menu to connect it.
    GreyHead 26 Feb, 2009
    Hi Becca800,

    Great, thanks. So, if we follow your technique of moving the existing OnSubmitAfter Code into the OnSubmit Before box, we can move the OnSubmit After Box *after* the Autogenerated Code, create and save the link from there. I have checked and you can get the article id from $row_jos_content->id

    Bob
    Becca800 26 Feb, 2009
    Yeah, that is the problem though, I am not getting the id at all, anywhere you place it. Also, if I put the post information for the jos_menu in the after submit box (while the post info for the article is in the before submit box), I can not get the link to be posted (any portion of it) in the jos_menu. I think, perhaps, that the autogenrated script may have a link parameter which may be screwing me up. Aside from that...still no ID. grrr.....

    Right now my before submit box is: (showing all)

    <?php
    if ( is_file($attachments['file_13']) ) {
        $name  = trim(JRequest::getString('zip', '', 'post')); // strip off any spaces from the ends
        $name .= "_".trim(JRequest::getString('state', '', 'post'));
        $name  = rawurlencode($name); // encode any special characters??
        if ( $debug) echo "name: ".print_r($name, true)."<br /><br />";
        $file_name_old = $attachments['file_13'];
        if ( $debug) echo "file_name_old: ".print_r($file_name_old, true)."<br /><br />";
        $file_name_new = dirname($file_name_old);
        $file_name_new .= DS.$name.'.'.jpg;
        if ( $debug) echo "file_name_new: ".print_r($file_name_new, true)."<br /><br />";
        rename($file_name_old, $file_name_new);
    }
    ?>
    <?php
    if ( is_file($attachments['file_14']) ) {
        $name  = trim(JRequest::getString('state', '', 'post')); // strip off any spaces from the ends
        $name .= "_".trim(JRequest::getString('zip', '', 'post'));
        $name  = rawurlencode($name); // encode any special characters??
        if ( $debug) echo "name: ".print_r($name, true)."<br /><br />";
        $file_name_old = $attachments['file_14'];
        if ( $debug) echo "file_name_old: ".print_r($file_name_old, true)."<br /><br />";
        $file_name_new = dirname($file_name_old);
        $file_name_new .= DS.$name.'.'.jpg;
        if ( $debug) echo "file_name_new: ".print_r($file_name_new, true)."<br /><br />";
        rename($file_name_old, $file_name_new);
    }
    ?>
    <?php
    $_POST['catid'] = '88';
    $_POST['sectionid'] = '6';
    $_POST['created'] = date("Y-m-d H:i:s");
    ?>


    by submit after is:

    Your agent info has been received for the town selected.
    <br/>
    <br/><br/>
    
    Please complete your registration by making payment with your Paypal account.    You have three choices: <br />
    <br />
    Either $5 per month:<br>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="2118344">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    <br><br>
    Or, $50 per year ($10 savings) subscription.  You will be charged yearly.<br>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="278243">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    <br>OR $50 for one year (no subscription).  Your page will not automatically renew after one year.
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="700122">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form><p>
    <b><u>If you do not have a paypal account, you can purchase one year with your credit card using Google Checkout.</u></b>
    <form action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/477731348107220" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm">
        <input name="item_name_1" type="hidden" value="1 Year MyTownRealEstateAgent.Com"/>
        <input name="item_description_1" type="hidden" value="One year town sponsorship."/>
        <input name="item_quantity_1" type="hidden" value="1"/>
        <input name="item_price_1" type="hidden" value="50.0"/>
        <input name="item_currency_1" type="hidden" value="USD"/>
        <input name="_charset_" type="hidden" value="utf-8"/>
        <input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=477731348107220&w=117&h=48&style=white&variant=text&loc=en_US" type="image"/>
    </form>
    
    <?php
    global $row_jos_content;
    $id = $row_jos_content->id;
    $city = $_POST['city'];
    $state = $_POST['state'];
    $_POST['type'] = 'component';
    $_POST['componentid'] = '20';
    $_POST['parent'] = '0';
    $_POST['checked_out_time'] = date("Y-m-d H:i:s");
    $_POST['published'] = '0';
    $_POST['checked_out'] = '0';
    $_POST['sublevel'] = '0';
    $link = "index.php?option=com_content&view=article&id=$id";
    JRequest::setVar('link', $link, 'post');
    $_POST['params'] = 'show_noauth=
    show_title=
    link_titles=
    show_intro=
    show_section=
    link_section=
    show_category=
    link_category=
    show_author=
    show_create_date=
    show_modify_date=
    show_item_navigation=
    show_readmore=
    show_vote=
    show_icons=
    show_pdf_icon=
    show_print_icon=
    show_email_icon=
    show_hits=
    feed_summary=
    page_title=Best ' . $city . ' ' . $state . ' Home Stager 
    show_page_title=0
    pageclass_sfx=
    menu_image=-1
    secure=0';
    ?>


    And the run order is as you suggested. I have changed this portion:

    $link = "index.php?option=com_content&view=article&id=$id";
    JRequest::setVar('link', $link, 'post');


    a thousand different ways!
    Max_admin 26 Feb, 2009
    Hi Becca800,

    I cant see the code to insert the new menu item ?

    show me your autogenerated code, you can get last inserted article id from there!

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    Becca800 27 Feb, 2009
    In the submit after box shown above, if you scroll down, this is the information that is posted to the menu.

    <?php
    global $row_jos_content;
    $id = $row_jos_content->id;
    $city = $_POST['city'];
    $state = $_POST['state'];
    $_POST['type'] = 'component';
    $_POST['componentid'] = '20';
    $_POST['parent'] = '0';
    $_POST['checked_out_time'] = date("Y-m-d H:i:s");
    $_POST['published'] = '0';
    $_POST['checked_out'] = '0';
    $_POST['sublevel'] = '0';
    $link = "index.php?option=com_content&view=article&id=$id";
    JRequest::setVar('link', $link, 'post');
    $_POST['params'] = 'show_noauth=
    show_title=
    link_titles=
    show_intro=
    show_section=
    link_section=
    show_category=
    link_category=
    show_author=
    show_create_date=
    show_modify_date=
    show_item_navigation=
    show_readmore=
    show_vote=
    show_icons=
    show_pdf_icon=
    show_print_icon=
    show_email_icon=
    show_hits=
    feed_summary=
    page_title=Best ' . $city . ' ' . $state . ' Home Stager
    show_page_title=0
    pageclass_sfx=
    menu_image=-1
    secure=0';
    ?>


    If the run order stays in the original order, with the autogenerated code last, everything posts perfectly and the menu item and article is there. The link shows up, just without the article id. I can't not get the article id to show up. If my autogenerated code is placed as suggested, everything still shows up except for the link, none of the link shows up.

    I have not altered the autogenerated code in any way:

    <?php
    		if($paramsvalues->dbconnection == "Yes"){			
    			$row =& JTable::getInstance("content", "Table");
    			srand((double)microtime()*10000);
    			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16);
    			$_POST["recordtime"] 	= JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" );
    			$_POST["ipaddress"] 	= JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" );
    			$_POST["uid"] 	= JRequest::getVar( "uid", $inum, "post", "string", "" );
    			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
    			if (!$row->bind( $post )) {
    				echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
    				exit();
    			}				
    			if (!$row->store()) {
    				echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
    				exit();
    			}			
    		}
    		?>
    		<?php
    		if($paramsvalues->dbconnection == "Yes"){			
    			$row =& JTable::getInstance("menu", "Table");
    			srand((double)microtime()*10000);
    			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16);
    			$_POST["recordtime"] 	= JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" );
    			$_POST["ipaddress"] 	= JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" );
    			$_POST["uid"] 	= JRequest::getVar( "uid", $inum, "post", "string", "" );
    			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
    			if (!$row->bind( $post )) {
    				echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
    				exit();
    			}				
    			if (!$row->store()) {
    				echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
    				exit();
    			}			
    		}
    		?>
    GreyHead 27 Feb, 2009
    Hi Becca800,

    ChronoForms tends to over-write the AutoGenerated Code box so it's safer to move the Menu Code into OnSubmit After. This code does work though you may need to change some of the parameter settings to suit your needs.
    <?php
    if($paramsvalues->dbconnection == "Yes"){ 
      global $row_jos_content;
      $data = array();
      $row =& JTable::getInstance('menu');
      $post =& JRequest::get("post" , JREQUEST_ALLOWRAW); 
      $data['link'] = "index.php?option=com_content&view=article&id=".$row_jos_content->id;
      $data['menutype'] = 'mainmenu';
      $data['name'] = $post['title'];
      $data['alias'] = $post['title'];
      $data['type'] = 'component';
      $data['published'] = 1;
      $data['params'] = '';
            
      if ( !$row->bind( $data ) ) {
        echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
        exit();
      }            
      if (!$row->store()) {
        echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
        exit();
      }         
    }
    ?>

    Bob
    Becca800 28 Feb, 2009
    I am about to give up. But I have to say that you guys rock with your customer support. I mean, you are really fantastic. I really appreciate all of the personal attention, and I realize you don't have to.

    The link still does not post. Neither the link portion nor the id. :? I will keep poking at it.
    GreyHead 28 Feb, 2009
    Hi Becca800,

    Not sure if it helps but the code I posted does successfully add a menu item in Joomla 1.5.9 with ChronoForms 3.1 RC2 (nothing special about either release though as far as I know). So you should be close.

    I'll add my modified submitcontent form here for you to experiment with.

    Bob

    [attachment=1]28-02-2009 09-06-25.png[/attachment]
    This topic is locked and no more replies can be posted.