Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Contact form with return results

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1353 Views
  • hmiller73
    Avatar
    Community Member
    4 Posts

    Contact form with return results Link to this post

    I have two text fields on my home page and a submit.

    I have it sending the data enter to the database just fine.

    I want to return what the user entered back to the screen like this> You sumitted $name, $email.

    How do I do this? Your turtorials you have on this site are so hard for a newbie to understand.

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: Contact form with return results Link to this post

    you could Redirect to a "finish" page that shows the "last" DB entry what you have.

    it could be a new page type. this page type could have a function in ..._controler like this:

       function ShowTheLastContact() {

          $Epics = new DataObjectSet();
          
          $result5 = DB::query("SELECT * FROM MyOwnContactForm ORDER BY ID DESC LIMIT 1");
          
          if($result5) {
             foreach($result5 as $value5) {
                $Datum = date("d.m.Y",$value5['Date']);
                $Uhrzeit = date("H:i",$value5['Date']);
                $eintraege = array(
                               'ID' => $value5['ID'],
                               'Name' => $value5['Name'],
                               'Email' => $value5['Email'],
                               'Message' => nl2br(htmlspecialchars($value5['Message'])),
                               'Datum' => $Datum,
                               'Uhrzeit' => $Uhrzeit
                               );
                $Epics->push(new ArrayData($eintraege));
             }
          }
          return $Epics;
       }

    and then you can show the last entry wioth this code in your .ss file of the page type:

    <% control ShowTheLastContact %>
    $Datum - $Uhrzeit<br ><br >
    $Email- $Uhrzeit<br ><br >
    From: <strong>$Name</strong><br ><br >
    Message: $Message<br ><br >
        <% end_control %>

    But this is not very good, because every user who visits THIS "finish" page can see the last entry.. so contact messages from other users.

    hmm.. you could make it, that this finish page just shows the last entry ONE TIME and then never again.
    (before: -> I HOPE U DONT USE THE "USERDEFINEDFORM PAGE TYPE".. because you can do much more with your system when u write the forms by your self. --> look at all threads i postet.. there must be some nice helpings..)

    soo..
    you should add a new DB field to your contact DB.. its called maybe: "ShowMe".. this should be set to "1" with an hidden field in the ContactForm.

    and now you can EDIT your function like this:

    ...
    ...
             foreach($result5 as $value5) {
                if($value5['ShowMe'] == 1) {
       
                   DB::query("UPDATE MyOwnContactForm SET ShowMe = '0' WHERE ID= '".$value5['ID']."');
                   $Datum = date("d.m.Y",$value5['Date']);
    ...
    ...
                } else {
                   $value5['ID'] = "";
                   $value5['Name'] = "";
                   $value5['Email'] = "";
                   $value5['Message'] = "";
                   $Datum = "";
                   $Uhrzeit = "";
                }

    do you understand? so "ShowMe" will set to "0" after first watch.. the finish page will be empty when someone goes to it. just, when you redirect to the page after inserting a new contactForm, then he will se it.

    ###########################
    #########################
    # ITS NOT TESTED - ITS NOT TESTED#
    #######################
    ######################
    #####################
    ####################
    ###################
    ##################
    #################
    ###############
    ##############
    ############
    ##########
    ########
    ######
    ####
    ##
    #

    1353 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.