• Resolved Steven

    (@spstieng)


    I’m creating some custom pages which contains forms.

    In my wordpress file (myTempalte.php), I have the following code:

    (...)
          <div class="contentbox470px floatLeft">
            <h3><?php _e('Foresl? butikk','StoreLocator');?></h3>
            <?php include_once 'includes/storeLocator/frm_store.php' ?>
          </div>
          (...)

    My frm_store.php looks like this:

    <form id="store_data_form" class="appnitro"  method="post" action="includes/process_frm_store.php">
      <input id="store_name" name="store_name" type="text" maxlength="40" value=""/>
      <input id="store_street1" name="store_street1" class="textfield65pc" value="" maxlength="50" type="text">
      <input id="saveForm" class="submitButton" type="submit" name="save" value="Submit Form" />
      <input id="clearForm" class="clearButton" type="reset" name="clear" value="Reset form" />
    </form>

    My process_frm_store.php looks like this:

    <?php
      $myDB = new DAL();
      $myDB->connect();
    
      if (isset($_POST['save']))
      {
        $formData =  array(
          "name"=> mysql_real_escape_string($_POST['store_name']),
          "street1"=> mysql_real_escape_string($_POST['store_street1'])
        $result = $myDB->addNewStore($formData);
        echo $result;
      }
    ?>

    My SQL function looks like this:

    public function addNewStore($formData)
      {
        $sql ="INSERT INTO sl_store(name, street1, street2, zipcode_id, phone, fax, www, email, opening_hours, active, descriptionID)";
        $sql .="VALUES('".
        $formData['name']."',".
          $formData['street1']."')";
    
       $this->query_result = mysql_query($sql, $this->conn);
    
       if($this->query_result)
        return $this->query_result;
      else
        return "Insertion failed";
      }

    My problem is that nothing happends.
    Nothing is inserted into the database, and the function is not returning anything.

    Are there any better ways of doing this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Steven

    (@spstieng)

    To simplyfy my question:

    How do I go about storing information from a qustom form to a database?

    Hi,

    Please use this plugin which will helpful to resolve the case..

    https://www.deliciousdays.com/cforms-plugin/

    Thanks,

    Shane G.

    Thread Starter Steven

    (@spstieng)

    I’m already using cForms II for other stuff.
    But I fail to see how this may solve my problem.

    I need to process the from data with my own scripts, so the data is stored in my own tables.

    Thread Starter Steven

    (@spstieng)

    I’ve partly fixed this, by having action=””.

    Then I moved the content of the process_frm_store.php, to the top of my form page.

    So for now, I’m setting this problem so ‘solved’.

    Hi.

    I am also battling the issue of custom form processing like you did 8 months ago. I wonder if you came to an understanding of this topic and maybe could give me a few tips.

    I am trying to get my form onto the sidebar. Which I did. Form action is set to “<?php echo $_SERVER[‘PHP_SELF’]; ?>”. So is the form action for the search form in the header (don’t know if this is a problem per se). Among the names that the standalone version of the form uses only $errors array makes me think of possible naming collisions when the form is inserted into a sidebar file. It always comes in unset if form is embedded into the sidebar (and it’s used to log input validation errors). In the standalone version it works fine. Do you think that could be the issue?

    Actually, any even simplistic walkthrough on how to embed a simple form into a sidebar would be greatly appreciated.

    Thanks for your time.
    Alex.

    Update:

    I got my problem fixed. I guess it was about a naming conflict or something similar. Previously, the validation.php file was being imported in the “header.php” and by the time it got to the sidebar something was happening. I moved the require statement into the top of the sidebar.php and it all works now.

    Technically, because the suspicion of naming conflict remains, I consider this a hack with possible consequences to the WP’s workings, but so far no issues have shown up. So I guess my case is “resolved” at this point as well.

    Should anyone have an idea of what could be going on here, please do comment.

    Thanks.
    Alex.

    Update:

    Actually, there are side effects. I just didn’t notice it right away since the blog is empty and the content area is pretty empty too. The form works, but upon submit it causes a 404 page to come up in the content area.

    Any ideas?

    Thanks.

    what’s the “action” of the form tag currently set to? In my dabbling with custom forms in WP, I’ve found relative URLs don’t work, I’ve had to either specify the absolute URL or nothing at all (“”).

    lysergic73

    (@lysergic73)

    I have the same problem, and I don’t understand how You fixed it. Can You publish your code? Or a simple example form..

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom form’ is closed to new replies.