Where does the posting go on?

Started by MLM, February 27, 2011, 04:14:35 PM

Previous topic - Next topic

MLM

I am wanting to add a featured work submission on the post.template. I added the layout but I can not figure out where and how it posts it to he db. I want to add my own MySQL query to insert into my own table.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

Post.php handles processing and sanitisation, before passing it to Subs-Post.php's createPost() function.

MLM

So if i have this on post.template:

<dl id="postAttachment2">
<dt>
Featured Work Submission:
</dt>
<dd class="smalltext">
Image URL: <input name="featured_work_image_url"></input>
</dd>

</dl>


How does it submit to the post.php? as what variable. and then how do i then pass it to subs-post to get put into db. I know how to use the smf db insert but just wondering how to get it there.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

It's submitted as a form to Post.php, in Post2() along with everything that's in the form. You'll see that appear in $_POST['featured_work_image_url'] if it was completed (if not, it will be empty)

What should it contain? Where's the field?

MLM

I dont get your question?

So it gets submitted to Post.php and then to subs-post.php?

Which function should i be putting it in? If i make my own function will it run it?

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

QuoteSo it gets submitted to Post.php and then to subs-post.php?

Yes. Like I said, Post.php will receive it first, in Post2(), it will check the content, sanitise it where necessary. It will throw it back to Post() if there's an error, or it will send it to createPost() in Subs-Post.php

You want help, here's the deal: you answer all the questions I ask, then I will answer yours. Because invariably the reason I'm asking is because the answer to my question will affect the answer to your question. So again, what should it contain, and where's the field going to end up in the database? (Is it per post, per topic, or something else?)

MLM

Sorry, It is going to be a url so i can sanitize it with regex. It is going in a separate table called featured_work_entries.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

In which case, you just need to add it to the table via a query in Post.php, just before the call to createPost() is actually made.

MLM

Is there a way to get the topic id that is being submitted?

What variable should i use to get the member name (not id)?

How do I return back to the message with everything intact if i get an "error" with the featured work?

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

You didn't say you wanted any of that stuff :P

So it's only on a new topic? (You really should be telling me this kind of stuff, you know, like I asked for?)

ascaland

You can retrieve the topic id using the $topic variable.
And since $user_id is accessible here you can easily just use $user_id['name'] (or $user_id['username'] if your looking for the username).

And if an error occurs you return Post2() with Post() using,
return Post();

And (someone correct me if im wrong) you need to set,
$_REQUEST['preview'] = true;
before returning to Post()?

Arantor

QuoteYou can retrieve the topic id using the $topic variable.

Only if there's already been a post and this is explictly a reply to it. If it's a new topic, $topic will not have been populated and will only exist after createPost() has been called, but will be in $topicOptions['id'] at that point. This seems to be the case of a new topic, and as such we can't rely on $topic.

QuoteAnd if an error occurs you return Post2() with Post() using,

Post2 already does this. If there's an issue with the content, you should be adding to $context['post_errors'] I think it is. That way, all content is sanitised first, returned back if there's an error, and after that point everything's known to be good.

This is why I wanted as much detail as possible before trying to help because Post2 alone is 800 lines of complexity, even before you look at the 1k lines of Post() as well, and their interplay is hideously complicated given everything that goes on.

ascaland

Quote from: Arantor on February 27, 2011, 08:28:33 PM
This is why I wanted as much detail as possible before trying to help because Post2 alone is 800 lines of complexity, even before you look at the 1k lines of Post() as well, and their interplay is hideously complicated given everything that goes on.

I agree, quite complicated to look at. Would,
$_REQUEST['preview'] = true;
need to be set by the way?

Arantor

Not if you do it properly and extend $context['post_errors'], which takes care of it all for you.

MLM

So if i wanted to return an error i could do this:
$context['post_errors'] = 'NOT AN IMAGE';

Also my thing is not working. If i put anything in my featured work inputs then it just directs me to some random board and doesnt post the topic.

I have my code above this: (in post.php)
// This is a new topic or an already existing one. Save it.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

QuoteSo if i wanted to return an error i could do this:

No, you have to add to the array, like all the others do, and do so to indicate an entry in $txt, like all the others do.


-sigh- I give up, you can't seem to answer quite simple questions, and I'm only going to get more frustrated by trying to help in this topic.

ascaland

Quote from: MLM on February 27, 2011, 08:45:26 PM
So if i wanted to return an error i could do this:
$context['post_errors'] = 'NOT AN IMAGE';

To return an error you would push a string value into the $post_errors array. The string value is what would be the suffix in the Errors language file. So, to help make things clearer if they arent already. You would push the error message as such,
$post_errors[] = 'posting_error_example';
And in the Errors.{language}.php file you would add,
$txt['error_posting_error_example'] = 'This would be displayed in the red warning box! Dont forget the error_ suffix.';

And the script would take care of the rest.

As for the second part, im not quite understanding but I think it would be easier if you showed us the code your using.

PS: Dont worry Arantor maybe I can take it from here if you need. :)

MLM

Alright i got my error done.

Arantor, why are you getting so frustrated I am understanding all of what you have said so far. Just explain a bit more.


Whenever i add stuff to the featured work inputs and try to post it just brings me to the board like it posted but nothing shows up..

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

#18
Quote from: MLM on February 27, 2011, 09:21:51 PM
Whenever i add stuff to the featured work inputs and try to post it just brings me to the board like it posted but nothing shows up..

In order for it to actually post you need to make sure you have the required form parameters in the script. Nevermind that part, I misunderstood. Can you please go over what your trying to do and post the code that doesnt seem to be working?

MLM


My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Advertisement: