Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Contact form with return results


Go to End


2 Posts   2324 Views

Avatar
hmiller73

Community Member, 4 Posts

28 February 2009 at 6:08pm

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.

Avatar
SalvaStripe

Community Member, 89 Posts

3 March 2009 at 1:25am

Edited: 03/03/2009 1:30am

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#
#######################
######################
#####################
####################
###################
##################
#################
###############
##############
############
##########
########
######
####
##
#