Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Reset on submit

Featured Replies

Hi guys,

 

If possible, I'm after a reset data PHP function, upon submit of contact form info. Redirecting the user isn't an option and I've been told not to avoid javascript if I can.

 

I'm not too clued up on with PHP so I'm not sure how to go about it, or if it's doable at all.

 

I'll post the code I've got so far, in case it's of any help. Sorry to ask a form related question, but it's not the form itself I'm stuck on so hopefully won't upset too many people...

 

Thanks..!

 

<?php 
           if (isset($_POST['submit'])) {
                   $to = "address@address.co.uk";
                   $subject = "Visitor Message";
                   $name_field = $_POST['name'];
                   $email_field = $_POST['email'];
                   $number_field = $_POST['number'];
                	$message = $_POST['message'];

                	$body = "From: $name_field\n E-Mail: $email_field\n Phone Number: $number_field\n Message: $message";

	            if (!$email_field == "") {
	            echo "Thank you for your message, $to will get back to you as soon as possible";
	            mail($to, $subject, $body);

				}

				else {
	                    echo "Please enter all your details to send message.";
	            	} 
	    }
       } ?>

Edited by Renaissance-Design
Please use the code button or tags to format your code.

You can't even redirect to the same page?

  • Author

You can't even redirect to the same page?

 

Woops, I should have mentioned that. Redirecting to the same page would be fine, that was my first idea. But then I have the problem of displaying a 'thanks'/'your message has been sent' notification.

 

Again, without javascript I can't see a solution, but I'm new to back end development so I don't really know what is/isn't doable at this stage.

 

One of our php programmers says I should just create a clone of the same contact page and put a thanks message in place of the form. It's a pretty nasty solution to be fair, but I haven't come up with anything better...

Ok, so if you redirect to the same page, the form will reset its self. From what I can see the echo should put the message on the page. Or you could use:

{print "Thank you for your message, $to will get back to you as soon as possible";}

Then you can put the php where ever on the page you want the message to display, or use css to do that.

  • Author

Ok, so if you redirect to the same page, the form will reset its self. From what I can see the echo should put the message on the page. Or you could use:

{print "Thank you for your message, $to will get back to you as soon as possible";}

Then you can put the php where ever on the page you want the message to display, or use css to do that.

 

It does..? I asked that question and was told no. One of us got the wrong end of the stick I guess, prob me. Anyway, I'll give it a go. Thanks..!

  • Author

Hmm, I'm having trouble getting the 'Thank you' message to appear on page refresh. Is there a way I can get the echo to occur with/just after page refresh..?

 

I'm sorry, my brain is going to need time to get used to the programming way of thinking...

 

 

This was my lame attempt:

 

<?php 
           if (isset($_POST['submit'])) {
                   $to = "email@email.co.uk";
                   $subject = "Visitor Message";
                   $name_field = $_POST['name'];
                   $email_field = $_POST['email'];
                   $number_field = $_POST['number'];
                	$message = $_POST['message'];

                	$body = "From: $name_field\n E-Mail: $email_field\n Phone Number: $number_field\n Message: $message";

	            if (!$email_field == "") {
	            mail($to, $subject, $body);
	            header ("Location: http://dev.site.com/contact-us.htm");
	            [b]echo "Thank you for your message, $to will get back to you as soon as possible";[/b]
				}

				else {
	                    echo "Please enter all your details to send message.";
	            	} 
	    }
       } ?>

Edited by Renaissance-Design
Please use the code button or tags to format your code.

What's the doing?

  • Author

My bad. Only meant to bold that echo to show where it was placed.

 

If anyone knows of any particularly good resources for learning php, they would be appreciated. Think this will take me a while.

 

 

 

 

PS: noted re: "Please use the code button or tags to format your code." edit. Will do...

  • Author

Rather than start another topic, I'll ask here. What's the story with styling echos/prints with CSS - is it possible, and if so, advisable..?

 

Basically I want to control the layout, colour, etc. of echoes [eg: "please enter a valid email address"] that prompt depending on validation.

 

I'll put my first attempt below, but I'm completely stabbing in the dark, with basically no PHP knowledge, so I could just be wasting my time.

 

 

Thanks..!

 

 

 

 

My idea was:

 

 

Echo a variable [assigned the relevant prompt] if validation comes back negative.

 

else
       {
       echo $warning_one;

 

Then assign the variables within a div to give me a CSS target.

 

<div class="warnings">
   <p><?php $warning_one = "please enter your name" ?></p>

 

Needless to say this doesn't work. The code runs as valid PHP, but I can't style the strings.

Edited by AGBrooks

  • Author

Looks like I had my echoes and vars the wrong way round. Couldn't help but think the echo needed to be in the else statement to be activated. Got a looong way to go with this stuff...

There are different ways to do it - as long as your css is correct it will work. Here's one way.

 

else
       {
       $warning_one = "please enter your name";
       echo '<div class="warnings">' . $warning_one . '</div>'; 

 

<div class="warnings">
   <p><?php $warning_one = "please enter your name" ?></p>

The above won't work because you're not echoing anything and you need a ; at the end of every php statement. The below will work

<div class="warnings>
<?php 
$warning_one = "please enter your name"; 
echo $warning_one;
?>
</div>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.