• I wrote a shortcode that presents the user with a form. I have the form post back to the same page. So

    http://somesite/?page_id=36 Takes the user to the page with the shortcode, and the user sees a form.

    user fills out form and selects the submit button

    form is posted back to http://somesite/?page_id=36.

    shortcode code gets exercised again, this time processing the form.

    I have an edit for some fields in the shortcode code, and if it fails, an error is added to the form. This all actually works well.

    If I pass validation, instead of re-presenting the user with the filled out form page as it should, I get a “query not able to find posts matching…”

    What I discovered is that instead of going back to http://somesite/?page_id=36 and using the assigned custom template, single.php is being used. But this is a page, not a post.

    I am having trouble tracking down where the error is occurring in template selection, or why. I have gone as far as to comment out most or all the code that get exercised if the form passes validation, but the error still occurs.

    Suggestions?

    $myId = '191';
    
    	$utility = new PersonUtility();
    	if (!isset($_POST['submitPersonForm'])) {
    		$id  = isset($_GET['id'])  ? trim($_GET['id'])  : '';
    		if(strlen($id) >= 2) {
    			$fileName = "wp-content/plugins/rootsPersona/" . get_option("rootsDataDir") . '/' . $id . '.xml';
    			if(file_exists($fileName)) {
    				$xml_doc = new DomDocument;
    				$xml_doc->load($fileName);
    				$p = $utility->paramsFromXML($xml_doc);
    			}
    		}
    		$p['action'] =  get_option('siteurl') . '/?page_id=' . $myId;
    		return $utility->showForm($p);
    	} else {
    		$p = $utility->paramsFromHTML($_POST);
    
    		if(strlen($p['id']) < 2) $msg = $msg . "<br />Invalid Id.";
    		if(strlen($p['name']) < 1) $msg = $msg . "<br />Name required.";
    
    		if(!isset($msg)) {
    
    			$fileName = "wp-content/plugins/rootsPersona/" . get_option("rootsDataDir") . '/' . $p['id'] . '.xml';
    			$xml_doc = new DomDocument;
    			if(file_exists($fileName)) {
    				$xml_doc->load($fileName);
    			} else {
    				$xml_doc->load("wp-content/plugins/rootsPersona/" . get_option("rootsDataDir") . '/templatePerson.xml');
    			}			
    
    			$xml_doc = $utility->paramsToXML($xml_doc, $p);
    			$xml_doc->save($fileName);
    			$p = $utility->paramsFromXML($xml_doc);
    
    			$msg = "<br />Saved.";
    		}
    		$p['action'] =  get_option('siteurl') . '/?page_id=' . $myId;
    		return $utility->showForm($p, "<div class='truncate'>" . $msg . "</div>");
    		//return $msg;
    	}
Viewing 1 replies (of 1 total)
  • Thread Starter ed4becky

    (@ed4becky)

    OK, I found it, but if someone can explain it that would be great.

    My form had a field called ‘name’ in it. Anytime I populated that filed, the error occurred. I changed ‘name’ to ‘personName’ and all is well.

    so having a form fields named ‘name’ interferes with something in WP.

Viewing 1 replies (of 1 total)
  • The topic ‘custom-page template ignored and single.php used.’ is closed to new replies.