Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Posts posted by alpine

  1. The variables from POST does not match the one used in email body,

    example: $apt1Field is declared from POST apt1 while inside email body it looks for variable $apt1

    /* Information Variables */
    $monthField = $_POST['month'];
        $apt1Field = $_POST['apt1'];
        $apt2Field = $_POST['apt2'];
        $apt3Field = $_POST['apt3'];
        $apt4Field = $_POST['apt4'];
        $apt5Field = $_POST['apt5'];
        $apt6Field = $_POST['apt6'];
        $totalField = $_POST['total'];
        $fromField = $_POST['from'];
        
        $body = <<<EOD
    <br /><hr /><br />
    Email: $month <br />
    708 Front St: $apt1 <br />
    708 1/2 Front St: $apt2 <br />
    218 N. Park Ave: $apt3 <br />
    220 N. Park Ave: $apt4 <br />
    1236 Sycamore St: $apt5 <br />
    1236 1/2 Sycamore St: $apt6 <br />
    Total: $total <br />
    From: $from <br />
    EOD;
    

  2. I would go for an AJAX aproach, adding picked boxes in a db by a php backend file - if done with pure php you must have each click reloading the page adding up the picked boxes in a session array or to db.

    Another variant is ofcourse to use javascript adding picked boxes either to a cookie or collecting all div id's in a hidden textfield that is treated by php on submitting the result page.

     

    im sure there are many ways of doing it, i would go for the AJAX method.

  3. I suspect you might be looking for something like this (simplified example)

    <?php
    
    // img_src.php
    
    $id = $_GET['id']; // make GET id db safe
    
    // query db for filename, content type and path based on requested photo id
    
    header('Content-Type: image/jpeg');
    echo file_get_contents('path/to/file/filename.jpg')
    
    ?>
    

     

    Then call img_get.php for each photo like this to display it

    <img src="img_src.php?id=foo" />
    

  4. It was an error on ending the heredoc syntax, but moving ; one line below is not the problem - adding space like this fixed it (showing from line 103)

      </tr>
    </table>
    </body>
    </html>
    
    EOD;
    
    echo $theResults;
    

     

    When that is said you dont need to run all this html through heredoc since you arent filling in any php variables at all as far as i can see

     

    *edit* EOD without space in front of it, shows poorly in the code block on this forum

    Also i recoment creating a better description rather than "Help Needed" etc when creating forum topics - most topics are created because the topic starter needs help.

  5. <?php
    
    $fields = array(
    'First_Name' => 'First Name',
    'Last_Name' => 'Last Name',
    'Card' => 'Card Number',
    'Old_Card' => 'Old Card Number'
    // and so on
    );
    
    $body = "We have received the following information from $_SESSION[username]:\n\n"; 
    foreach($_REQUEST as $a => $b){
    if(array_key_exists($a, $fields) && !empty($b)){
       $part1 .= sprintf("%20s: %s\n", $fields[$a], $b);
    }
    }
    
    ?>
    

  6. It is no problem to show the form again after it is submitted if an error exists, post form to the same file as you have the form and fill the form with the posted variables.

     

    Example:

    <?php
    
    $complete = false;
    $empty_arr = array();
    
    foreach($_POST as $fieldname => $fieldvalue)
    {
      if(empty($fieldvalue))
      {
        $empty_arr[] = $fieldname." was left empty";
      }
      ${$fieldname} = $_POST[$fieldname];
    }
    
    if(!empty($empty_arr))
    {
      echo "<ul><li>";
      echo implode($empty_arr, '</li><li>');
      echo "</li><ul>";
    }
    else
    {
      // no empty fields, prosess posted values already defined as $fielnames
      $complete = true;
    }
    
    if($complete == false)
    {
    echo <<<_HTML
    
    <form method="post" action="{$_SERVER['PHP_SELF']}">
    <p>Name:<br /><input type="text" name="name" value="$name" /></p>
    <p>Email:<br /><input type="text" name="email" value="$email" /></p>
    <p><input type="submit" name="submit" value="Send" /></p>
    </form>
    
    _HTML;
    }
    
    ?>
    

     

    When you mention instant red border on error fields that is mainly pure javascript validation, one example is http://www.formassembly.com/wForms/

  7. I prefer to expect variable either as POST or GET and try to avoid the possibility for both, if you however expect both you could use REQUEST

    <?php
    
    if(empty($_REQUEST['var']))
    
    ?>
    

    as empty returns false also if 'var' is not set, so it checks both if it is set and that its not empty

  8. I would never rely on javascript alone as this is easily manipulated if someone want to do so, you should always validate with php.  AJAX is my preferred method if validating along the form since i can ask the same php functions both times.

  9. You can start with this

    <?php
    
    function Check($data){
      // this example allowing: A to Z a to z 0 to 9 . , space(s) - @ _
      if(preg_match("/^[-A-Za-z0-9.,\s@_]+$/", $data))
      return true;
      else
      return false;
    }
    
    if(!Check($_POST['text'])){
    echo "Illegal input found";
    }
    
    ?>
    

  10. Its better to use a switch statement tho

    <?php
    
    switch($_GET['page']){
    case 'home':
    // include or whatever on home
    break;
    case 'news':
    // include or whatever on news
    break;
    default:
    // include or whatever when $_GET['page'] doesnt match other case, or dont exist
    }
    
    ?>
    

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.