Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Ask A Question MOD, (About an article) need help to finish...  (Read 5200 times)

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine

Hello to all:  ;)

I was wondering if some php savvy genius can help me finish a MOD i am working on, i would greately appreciate it. A client requested that apart from the comments function, he wishes his users to be able to post questions about the articles. (His website is about spirituality so he wants people to ask things he can answer to regarding the articles users read).

So i downloaded a generic free php form script that mails the question to the website's admin regarding a specific article. I was able to add the "ask question" link at the bottom of the article following instructions from another mod, the "print article" MOD, somewhere else in this forum. That i did in Snews.php, no problem there.

So far so good. When the user clicks on a link that says "ask a question" below any article, he is taken to a form where he enters his name, e-mail and... the question, of course!  :lol: Thanks again to the previously mentioned MOD, i was also able to print on the form the article's title, quieried dynamically from the database. So the user can see the title of the article in his form so he doesn't have to actually tell the webmaster what article is he asking questions about. Up to this point everything is comming out roses.

However, i have been unable to figure out how to print the article's title in the e-mail that the webmaster receives after the user has submitted the form. If i could put the article's title in the subject line or at the top of the e-mail message, the webmaster would also know what article the question is about. I am a newbie in php, i understand some of it but after long hours trying this little trick i give up. The MOD is almost finished and all it needs is this "e-mail-the-title-of-the-article" to the webmaster and its done. Can somebody lead me in the correct path? I will add your help in the credits line of the mod too!!!!

Thanx for any help i can get!

BTW: I also finished another MOD that works great. Its a completely new "Send Article to a Friend" MOD with a beautiful CSS styled form, prints the article's title on the form for the user to drool at, and sends the article's full URL vía mail to the friend. I will organize the files and zip them and post it here.


MiXElle  ;)
Logged
Slutty alright but pretty and with BRAINS

mattonik

  • Full Member
  • ***
  • Karma: 7
  • Posts: 123
    • http://www.mattonik.sk
Ask A Question MOD, (About an article) need help to finish...
« Reply #1 on: June 07, 2007, 10:41:19 pm »

well how about to try invisible input?
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Ask A Question MOD, (About an article) need help to finish...
« Reply #2 on: June 08, 2007, 03:18:31 am »

Quote from: mixelle
BTW: I also finished another MOD that works great. Its a completely new "Send Article to a Friend" MOD with a beautiful CSS styled form, prints the article's title on the form for the user to drool at, and sends the article's full URL vía mail to the friend. I will organize the files and zip them and post it here.
Unfortunately I can't help ypu with your current query, but be sure to post this in the MODs/ADDONS forum wont you ;)  Sounds great!
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine
Ask A Question MOD, (About an article) need help to finish...
« Reply #3 on: June 08, 2007, 03:39:39 pm »

Quote from: mattonik
well how about to try invisible input?
Do you mean as a hidden field in the form? i tried that, which makes a lot of sense, but while i was able to output the article's title in the form for the user filling out the form to see, quiried dynamically from the database, i haven't been able to "send" the article's title in the e-mail when the user submits the form. Aw c'mon guys, this cannot be too difficult! The "Printer friendly Mod" posted in the SNews 1.5 Mods section quieries the database an outputs things such as the website's title, the article's title, even the whole article on screen. I based my mod on that, so when the user clicks on"Ask a Question" at the end of the article, he is taken to a form where he can see the article's title and fill out a few fields. The form has a captcha scheme to validate the user as human.

The missing part is sending the article's title along with the e-mail that is sent when the user submits his question. The mystery is, what variable to put in the hidden form field?

Quote
?">
Let me try and make this a little bit easier. Between the form tags and inside a table cell i added this slightly modified bit of code to query the database:

Quote
/* Database query. */

include ("snews.php");

if (!empty($_GET)) {extract($_GET);} else if (!empty($HTTP_GET_VARS)) {extract($HTTP_GET_VARS);}
if (!empty($_POST)) {extract($_POST);} else if (!empty($HTTP_POST_VARS)) {extract($HTTP_POST_VARS);}
?>

$numrows=0;
if(!isset($id)){ $id=""; }
connect_to_db();
if ($id <> "") {
$query = "SELECT * FROM articles WHERE id = $id";
$shorten = 200000;
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo "".stripslashes($r['title']). "";
}
if(!isset($numrows)) { $numrows=0; }
}
else {
echo "The article's ID was not set. Please try again. ";}
?>
So the line that outputs the article's title in my form would be:
Quote
echo "".stripslashes($r['title']). "";
.

Now i need to have the article's title sent out in the form. I am trying something like this:
Quote
or something similar along this logic.... i'm a bit confisued to which is the right variable that goes in there...

Share Article With Friend is comming up and will be posted later today.... :D
Logged
Slutty alright but pretty and with BRAINS

mattonik

  • Full Member
  • ***
  • Karma: 7
  • Posts: 123
    • http://www.mattonik.sk
Ask A Question MOD, (About an article) need help to finish...
« Reply #4 on: June 08, 2007, 04:33:57 pm »

use $r['title'] for value
it must be working when outputing article title works, why shouldn't work with form?
Logged

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine
Ask A Question MOD, (About an article) need help to finish...
« Reply #5 on: June 08, 2007, 05:57:34 pm »

Quote from: mattonik
use $r['title'] for value
it must be working when outputing article title works, why shouldn't work with form?
Hi Mattonik:

When i use the line:

Quote
Nothing is output. Blank. I presume this is because the article's title is being quieried everytime you call the form, so you need the entire query to work. In the query i don't see a variable that sets the article's title for good, what i see is a result. We need a variable in the likes of $title or something like that...

I tried:

Quote
And it indeed outputs the Number ID of the article, which is an advance. Maybe something like:
Quote
would do the trick... but
Quote
Did not work either.... However the previous line shows that the answer to the riddle lies something around the ID variable, which seems to have been properly called in the query. In PHP can i do something like this?

Quote
get my idea? Thanx for your help, will keep trying...


 ;)
Logged
Slutty alright but pretty and with BRAINS

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine
Ask A Question MOD, (About an article) need help to finish...
« Reply #6 on: June 09, 2007, 12:59:43 am »

Hello Bakercad:  ;)

Could you help me with the right sintax? I tried your solution which makes a lot of sense  but if i didn't get php syntax errors i would get no output. If i can output the article's title the same way i was able to output the article's id explained in my previous post, like this:

Quote
then i can send it as a hidden form field. Hmmmm, to further aid all those who are helping, i found in SNews the function for the title. Maybe with the query already working in my form and this bit of code we can shed some light into achieving what i intend. Here it goes...
Quote
function title() {
   echo '';
   $categorySEF = get_id('category'); $articleSEF = get_id('article');
   $categoryName = retrieve('name', 'categories', 'seftitle', $categorySEF);
   $articleTitle = retrieve('title', 'articles', 'seftitle', $articleSEF);
   if (!empty($articleTitle)) {$title = $articleTitle.' - ';}
   if (!empty($categoryName)) {$title .= $categoryName.' - ';}
   $title .= s('website_title');
   echo ''.$title.'';
   echo '';
   if (!empty($articleSEF)) {
      $query = "SELECT * FROM ".db(prefix)."articles WHERE seftitle = '$articleSEF'";
      $result = mysql_query($query);
      while ($r = mysql_fetch_array($result)) {$dmeta = $r['description_meta']; $kmeta = $r['keywords_meta'];}
   }
   echo '';
   echo '';
   if ($_SESSION[db('website').'Logged_In'] == token()) {js();}
}
I played with this function for a while with no avail. The answer to the riddle may be here, but i still insist that if the query actually outputs the article's title in the form, there has to be a magic php little function that will also echo the title anywhere else in the form, since the query is already there, as a hidden field, for example, to send it in the e-mail when the user submits the form. Its a great MOD but it would be incomplete without this part, as the admin will receive the question without knowing to which article the user is referring to. If after the query i write anywhere in my form the line:

Quote
And it outputs the ID number of the article in question, there must be a similar way to echo the title. I am tempted to post the MOD as is and ask someone if he/she can finish this little part... :/  I've been working on this for two days now...  :(

I'm such a newbie in PHP (had classes for only 2 weeks) all i can echo to this point is "hello World"... :lol:
Logged
Slutty alright but pretty and with BRAINS

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Ask A Question MOD, (About an article) need help to finish...
« Reply #7 on: June 09, 2007, 01:42:26 am »

mixelle, that function is for the generation of the and a large portion of the of the html required for the page.

The retrieve function allows you to get the article title.
Don't confuse the varying number of $title variables you may see throughout snews ...

When you see $title in the title() function, that instance of the variable $title can only be used within that function, and contains only what that function puts in it.

Now, if you use the retrieve as bakercad has it above, in your mod function, and assign it to $title, then in that function, $title contains the article title.

so to see if you are retrieving the article title...
instead of
Quote
try

Quote
but to pass this to email, you will need to have this information in a hidden field as bakercad has suggested.
Logged
Of all the things I have lost, it is my mind that I miss the most.

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine
Ask A Question MOD, (About an article) need help to finish...
« Reply #8 on: June 09, 2007, 03:46:16 am »

Quote
Yeeeeeeeessssssssssss!!! Philmoz a huge kiss to you!!!  :-*
You are absolutely right. It was right under my nose, Bakercad had suggested it but i couldn't get the syntax right, it was all my damn syntax typos... :rolleyes:

THANK YOU VERY MUCH!

Now that i am in my second week of php self-paced learning, i can write the following:

Quote
$title = retrieve('title','articles','id',$id);
echo $ title;
?>
That outputs the title alrighty. Meaning i can output $title in the hidden form of the field. We'll see ;)

OK. So i owe it to both of you for finishing this MOD. I am going to credit you guys when i post it. Now i am going to check the form hidden part of this wonder and when all that is set, will publish. Got a MOD to finish!

Thanx SO MUCH again! ;)

I wish a client knew about all the trouble one goes to fulfill their needs, and all they do is complain about this and that. Sigh....

:|
Logged
Slutty alright but pretty and with BRAINS

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Ask A Question MOD, (About an article) need help to finish...
« Reply #9 on: June 11, 2007, 08:20:24 am »

just a programming tip for you...

single quotes vs double quotes

see this line in you wom mod
case ($tag == 'tellafriend'): echo "Tell A Friend";break;

in the echo, you have used only double quotes, requiring you to have to escape the quotes that are required by html.

it could have been written--
case ($tag == 'tellafriend'): echo 'Tell A Friend';break;
Note the position I have placed the single quotes.

Also, in your mod pack, you have commented about the possibility of using an image.
If you use the language variables to create the visual item (text or image), then it makes an easier place for people to switch from one to other, depending on site requirements, instead of having to hunt it down each time.

for eg. (if embedded in snews)
add to // LANGUAGE VARIABLES at bottom before the  } return $l[$variable]; line--
Quote
/* Tell a friend addon */
$l['tellafriend'] = 'Tell a friend'; /* ''; */
/* end - Tell a friend addon */
(the   /* ''; */ is the commented out img html, and isn't active.)
or you could create a language function in your mod if it is called seperate from snews.
and in the case line, you would then alter it to
Quote
case ($tag == 'tellafriend'): echo ''.l('tellafriend').'';break;
If you decide to make it an image, change text/language, just alter $l['tellafriend']
Just some things to consider as you learn snews and php ;)
Logged
Of all the things I have lost, it is my mind that I miss the most.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Ask A Question MOD, (About an article) need help to finish...
« Reply #10 on: June 11, 2007, 08:26:51 am »

and just looked at the template file...
This file uses php shortcuts, only available if short-tags is enabled in php.ini, which is not always the case.

for eg

in long version is
Logged
Of all the things I have lost, it is my mind that I miss the most.

Jessica Michelle

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
  • DivaDivine
Ask A Question MOD, (About an article) need help to finish...
« Reply #11 on: June 12, 2007, 02:06:03 am »

Quote from: philmoz
and just looked at the template file...
This file uses php shortcuts, only available if short-tags is enabled in php.ini, which is not always the case.

for eg

in long version is
Thanks great suggestions. All these changes have been posted courtesy of your wisdom in my WOM Tell A Fiend MOD post under MODS&Addons in the forum.
Logged
Slutty alright but pretty and with BRAINS