We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Posting to a weblog without being logged in.

Development and Programming

Ben McNelly's avatar
Ben McNelly
20 posts
17 years ago
Ben McNelly's avatar Ben McNelly

hi, I have a module that among other things, saves the output of a form to a weblog. Problem is this form can also be submitted by people who are not logged in. It works perfect as long as your logged in, as a test i took away “members” permission to publish to the weblog that this module saves the form to, and sure enough.

Here is how we are saving the form to the weblog.

function add_application()
{
    global $DB, $IN, $LOC;

    
    // get weblog id        
    $query = $DB->query("SELECT weblog_id FROM exp_weblogs WHERE blog_name = 'applications'");
    
    if ($query->num_rows == 0)
    {
        return;
    }
    
    $weblog_id = $query->row['weblog_id'];
    
    
    // set title
    $title = $IN->GBL('first_name', 'POST')." ".$IN->GBL('last_name', 'POST')." - ".$IN->GBL('application_type', 'POST');
    
    
    // get application weblog fields
    $fields = array();        
    $query = $DB->query("SELECT * FROM exp_weblog_fields JOIN exp_field_groups ON exp_weblog_fields.group_id = exp_field_groups.group_id WHERE group_name = 'Applications'");
        
    foreach ($query->result as $row) 
    {
        $fields[$row['field_name']] = "field_id_".$row['field_id'];    
    }    
    
    
    // convert inputed data to custom fields
    foreach ($fields as $field_name => $field_id)
    {
        // if custom weblog field does not exist then unset
        if (isset($_POST[$field_name]))
        {
            $_POST[$field_id] = $_POST[$field_name];
        }
    }
    
    
    // add extra data
    $_POST['weblog_id'] = $weblog_id;
    $_POST['title'] = $title;
    $_POST['entry_date'] = $LOC->set_human_time($LOC->now);
    
    // set return url
    $_POST['return_url'] = 'application/sent ';
    
    
    // insert
    if ( ! class_exists('Publish'))
    {
        require PATH_CP.'cp.publish'.EXT;
    }
                    
    $PB = new Publish();
            
    $PB->submit_new_entry(FALSE);    
}

So how do we get this to still publish to the weblog for non-logged in users??

       
Ben McNelly's avatar
Ben McNelly
20 posts
17 years ago
Ben McNelly's avatar Ben McNelly

Is there a better way than cp.publish, or way that let’s get around not being logged in to publish? We are just wanting to be able to bring up the data like it’s a weblog so we can easily write views to sort and display it.

       
Brian M.'s avatar
Brian M.
529 posts
17 years ago
Brian M.'s avatar Brian M.

I would probably write an extension (and extension hook) instead of instantiating the publish class itself - I’m always scared to start calling classes directly, who knows what development plans are going forward for EE… As for the logged in part, how about registering a new user in the system named “Guest” or “Anonymous”. Then , in your extension, you check to see if the person if logged in. When they aren’t, assign the entry to that Guest user so it technically has an author?

EDIT - actually you don’t even need to have your extension do that probably. On page load you could see if the person is logged in - if not then in the form itself set the user to your Guest user.

       
Ben McNelly's avatar
Ben McNelly
20 posts
17 years ago
Ben McNelly's avatar Ben McNelly

OK I will give that a shot 😉

I will let you know how it goes.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.