SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Call to undefined function form() ?

    Hi,

    I have the following code however the form('reset-password', part creates an error. Call to undefined function form()

    I have looked up was this error is and the only suggestions I can find is that it is returned due to a spelling error. However I cant see any spelling errors. Does anyone have any suggestions on how I can fix this please?



    Code:
        /// URL is defined as the root of the URL used in the email, in this example it would be "http://example.com/"
        URL . "resetpassword.php?page=reset-password" . urlencode($userid) . "&key=" . urlencode($key) . "\r\n" .
        "\r\n" .
        "Kind regards,\r\n" .
        "\r\n" .
        "The example.com Web Site"
      );
    }
    
    // form, input_hidden, table, tr, td, label, input_password and input_submit are my own wrappers which return the appropriate HTML with escaped values where required.
    echo
      form('reset-password',
        input_hidden('userid', $_GET['userid']) .
        input_hidden('key', $_GET['key']) .
        table(
          tr(
            td(label('New Password')) .
            td(input_password('new_password', ''))
          ) .
          tr(
            td(label('Confirm Password')) .
            td(input_password('confirm_password', ''))
          )
        ) .
        input_submit('ok', 'OK')
      );

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Is this part of a framework? Are you trying to echo form( out to the browser?

    If so you are missing the quotes around your string, or you can use HEREDOC and do something like so
    PHP Code:
    echo <<<FORM_OUTPUT
      form('reset-password',
        input_hidden('userid', 
    $_GET['userid']) .
        input_hidden('key', 
    $_GET['key']) .
        table(
          tr(
            td(label('New Password')) .
            td(input_password('new_password', ''))
          ) .
          tr(
            td(label('Confirm Password')) .
            td(input_password('confirm_password', ''))
          )
        ) .
        input_submit('ok', 'OK')
      );
    FORM_OUTPUT; 

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Its for a password reset script which sends an email an echoes a link.

    I haven't used HEREDOC before. How do I add quotes to the string?

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sounds as if include files have not been included.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    I haven't used HEREDOC before. How do I add quotes to the string?
    Just depends on if this is for a Client UI framework or a backend framework, do you need to include other files (as @Cups ; suggested)?
    If you do, you can ignore my comment, as it would no longer apply.

    If you do need it for a Client UI framework, you can either use the HEREDOC statement I posted earlier, or you can put the Client UI code in quotes like so
    PHP Code:
    echo "
      form('reset-password',
        input_hidden('userid', 
    $_GET['userid']) .
        input_hidden('key', 
    $_GET['key']) .
        table(
          tr(
            td(label('New Password')) .
            td(input_password('new_password', ''))
          ) .
          tr(
            td(label('Confirm Password')) .
            td(input_password('confirm_password', ''))
          )
        ) .
        input_submit('ok', 'OK')
      )"


  6. #6
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I tried both the quotes and HEREDOC and couldn't get either to work.

    This is the error Call to undefined function form() do I need to isolate the form in some way?

    Code:
    // $userid must be an integer that matches a valid user's ID.
    function reset_password($userid) {
      query("delete from reset_password where userid = $userid");
      $key = substr(base64_encode(crypt('', '')), 0, 32);
      query("insert into reset_password values ($userid, '$key', " . time() . ")");
      // fetch is my own wrapper function to fetch a row from the query.
      $f = fetch(query("select username from organisermembers where id = $userid"));
      // smtp is my own function, you will probably want to use the php mail function.
      smtp(
        "do-not-reply@example.com", // sender
        $f['username'], // recepient
        "From: The example.com Web Site <do-not-reply@example.com>\r\n" . // email headers
        "To: {$f['username']} <{$f['username']}>\r\n" . // actual email address <put a nice friendly name in here if you have the the information>
        'Subject: Reset Password' . "\r\n" .
        "\r\n" .
        "Hello\r\n" . // email body
        "\r\n" .
        "A request has been made to reset your example.com web site password.\r\n" .
        "\r\n" .
        "To complete the request, click on the following link within 48 hours of the transmision of this email and follow the on screen instructions.\r\n" .
        "\r\n" .
        /// URL is defined as the root of the URL used in the email, in this example it would be "http://example.com/"
        URL . "resetpassword.php?page=reset-password" . urlencode($userid) . "&key=" . urlencode($key) . "\r\n" .
        "\r\n" .
        "Kind regards,\r\n" .
        "\r\n" .
        "The example.com Web Site"
      );
    }
    
    // form, input_hidden, table, tr, td, label, input_password and input_submit are my own wrappers which return the appropriate HTML with escaped values where required.
    echo 
      form('reset-password/ok',
        input_hidden('userid', $_GET['userid']) .
        input_hidden('key', $_GET['key']) .
        table(
          tr(
            td(label('New Password')) .
            td(input_password('new_password', ''))
          ) .
          tr(
            td(label('Confirm Password')) .
            td(input_password('confirm_password', ''))
          )
        ) .
        input_submit('ok', 'OK')
      );
    
     
      
      // The reset_password_message function displays the message to the user.
    if (!isset($_POST['userid'])) {
      reset_password_message('You must enter a user ID. Please try again.');
    } else if (!isset($_POST['key'])) {
      reset_password_message('You must enter a key. Please try again.');
    } else if (!isset($_POST['new_password']) || !$_POST['new_password']) {
      reset_password_message('You must enter a new password. Please try again');
    } else if (!isset($_POST['confirm_password']) || $_POST['new_password'] != $_POST['confirm_password']) {
      reset_password_message('The new password and the confirmation do not match. Please try again.');
    } else if (!$f = fetch(query("select time from reset_password where userid = " . (integer)$_POST['userid'] . " and key = '" . escape($_POST['key']) . "'"))) {
      reset_password_message('The user ID and key pair are invalid. Please try again.');
    } else if ($f['time'] < time() - 60 * 60 * 24 * 2) { // 60 seconds * 60 minutes * 24 hours * 2 days (48 hours as explained in the email sent to the user above).
      reset_password_message('The user ID and key pair have expired. Please try again.');
    } else {
      query("update organisermembers set password = '" . crypt($_POST['new_password']) . "' where id = " . (integer)$_POST['userid']);
      reset_password_message('Your password has been reset. Please login.');
    }
    
    ?>

  7. #7
    SitePoint Member blogaddition's Avatar
    Join Date
    Sep 2012
    Location
    India
    Posts
    23
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you using a php framework or something else. If you are using only core php then tell me, I will give you exact code.

  8. #8
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi Blogaddition,

    Its core PHP, Im trying to keep it as simple as possible as I am not that expierienced with PHP.

  9. #9
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Bottom line is, there is no function named "form" defined. Where is that function defined? If it's in a different file, you have to include that file.

    In your last piece of code posted, I see the function reset_password is defined. Somewhere you need functions named

    form
    input_hidden
    tr
    td
    input_submit
    input_password
    label

    Or are those supposed to be javascript functions?
    - Robert


Bookmarks

Posting Permissions

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