Results 1 to 6 of 6

Thread: Problem passing parameters from form to function

  1. #1
    Join Date
    Aug 2004

    Question Problem passing parameters from form to function

    I'm presently redoing my website, and I'm using wordpress as a CMS. I wish to re-use a chatboard I had on the old website, but I'm having problems passing the variables through. What could be the problem?
    Here's my form:

    HTML Code:
    <form action="http://www.mydomain.com/chat/post.php" method="post" id="comment-form">
    	<p style="float:left"><label for="user_name">Nom ou pseudo&nbsp;:</label><br />
    	<input name="user_name" id="user_name" type="text" size="25" maxlength="255" /></p>
    	<p style="float:right"><label for="user_email">URL&nbsp;:</label><br />
    	<input name="user_email" id="user_email" type="text" size="25" maxlength="255" value="http://" /></p>
    	<p><label for="chat_body">Commentaire&nbsp;:</label><br />
    	<textarea class="center" id="chat_body" name="chat_body" cols="57" rows="3"></textarea>
    <p class="center pad"><input type="submit" class="submit" name="Sign" value="Go !" size="25" /></p>
    That's my post.php file:

    PHP Code:
     // my connexion parameters to DB here

    // do a basic check, don't let user submit a blank entry.

    if ($user_name == '' || $chat_body == '' )
    "error message";


    // strips off weird characters and HTML tags
    $allowable_tags "<B><I><LI><OL><P><U><UL><S>";
    $chat_body strip_tags($chat_body$allowable_tags);

    // do check here

    $last_entry "select * from shoutbox order by id desc limit 1";
    $check mysql_query($last_entry);

    while (
    $row mysql_fetch_array($check))
    $oldname $row["user_name"];
    $oldmsg $row["chat_body"];

    // compare the values of old and new entry
    if ($oldname == $user_name && $oldmsg == $chat_body// means the name and msg entered is the same
    "Another error message here";

    // check comments :

    * Check presence of 'bad strings'.
    function contains_badwords($string) {
    $bad_words = array(
    // here, an array of spam words          
    $bad_words as $bad_word) {
    eregi($bad_wordstrtolower($string))) {

    if (
    contains_badwords($chat_body)) {
    header("HTTP/1.0 200 OK"); //Send out a content is good/complete to make it look as though things have gone well
    header('Refresh: 1; url=http://spam.abuse.net/'); //polite redirect
    header("Connection: close");

    if (
    contains_badwords($user_name)) {
    header("HTTP/1.0 200 OK"); //Send out a content is good/complete to make it look as though things have gone well
    header('Refresh: 1; url=http://spam.abuse.net/'); //polite redirect
    header("Connection: close");

    // check IP
    $user_ip $_SERVER['REMOTE_ADDR'];

        include_once (
    $check checkBan($user_ip);
        if (
    $check == 1)
    "Another error message here";
     if (
    $check == 0)
    // insert into database
    $q "insert into shoutbox (id,user_name,chat_body,user_email,date_time,user_ip) VALUES ('','$user_name','$chat_body','$user_email',now(),'$user_ip')";
    $result mysql_query($q);
    if (
    // success so redirect user to view shoutbox.
    $siteurl 'http://www.mydomain.com/tagboard'// it's a wordpress template, hence the lack of "php" extension
    header('Location: '.$siteurl);
    I obviously got rid of the unimportant stuff, like the spam words and the error messages, in order to post only the essential.
    When I test it, I get the first error message, which means the infos aren't passed through.

    So, I was thinking I could maybe put everything in one file, but I'm clueless to how to do that. I tried making my post.php content into a function and calling the function on submit, but it didn't work.
    I'd really appreciate all advice!


  2. #2
    Join Date
    Aug 2004
    I think I found out a solution! I'm not sure it's the best or anything, and I still would like to put everything in the same file (it would be easier to manage), but at least now it's working.

    No idea why, but on the last website, everything worked properly, and on this one, I had to add this:
    PHP Code:
    $user_name mysql_escape_string($_POST['user_name']);
    $user_email mysql_escape_string($_POST['user_email']);
    $chat_body mysql_escape_string(strip_tags($_POST['chat_body'])); 
    I put that at the beginning of my post.php file.

    I tried putting all together like that:

    HTML Code:
    <form method="post" action="<?php echo($_SERVER['PHP_SELF']) ?>">
    and then:
    PHP Code:
    function posttag () {
    // the content of my post.php file here

    It didn't work, the data didn't go through (but it didn't output an error message either).
    Last edited by Ness_du_Frat; 11-24-2013 at 02:26 PM.

  3. #3
    Join Date
    Mar 2007
    You are missing enctype="multipart/form-data" from your form tag.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Aug 2004
    Thanks. What is it for, exactly? Is it really so bad to forget it? (I never put it in any of my forms)
    One more reason why I'd like everything in the same file is to get these cool ajax fade in error messages, instead of simply echoing the php ones. I've tried to find a tutorial for that, but I only get full scripts and such, and they are all very different, so it's difficult to learn from these.
    I only want to display the error message below the form. I'm not sure where to start.

  5. #5
    Join Date
    Aug 2004
    Seems like I can't do anything with my error messages as long as my post.php is in another file... Since all the errors are handled in the post.php file, they open in their own page.
    Still looking for advice on how I can put everything in the same page (wordpress page, so no .php extension, and no direct link to the file possible since it's a template, so it will lead nowhere).

  6. #6
    Join Date
    Mar 2007
    When posting a file or page, you need to tell the browser what it is that it is sending, is it binary data, plain text or data in a URL.

    Most post errors can be resolved with the addition of the enctype directive added.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15812 seconds
  • Memory Usage 2,936KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_html
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates