Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By sunfighter

Thread: Two small problems about a simple submit form

  1. #1
    New to the CF scene
    Join Date
    May 2014
    Location
    London, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Two small problems about a simple submit form

    Hey
    Firstly, I have a form on my website for people applying to do various things for the site but its just set the redirect to the homepage. I was wondering if there is anyway I can set it to not redirect but just remove the form and say "thanks your message has been received" this ones not so much of a problem right now but once the website is up and running we are thinking of putting a radio on it and it would be handy for a requests panel without having to refresh each time

    Also I found the code online and its fine I was just wondering if there is a way to tweak it because it has a feature to make all fields required or not and even if i put it as yes I tested and it wont pick up check boxes as not being selected so I was wondering if there is a way I could make it notice this and flash up saying you must pick at least one or something

    thanks

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,556
    Thanks
    75
    Thanked 105 Times in 104 Posts
    Use a IF and Else condition statement.

    PHP Code:
    if (isset($_POST['submit'])) {
    //Don't show form
    echo 'Form sent successfully';
    }

    else {
    //Original coding with form

    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by myfayt View Post
    Use a IF and Else condition statement.

    PHP Code:
    if (isset($_POST['submit'])) {
    //Don't show form
    echo 'Form sent successfully';

    No, you NEVER use the submit button to process a form because internet explorer has a bug. This means the submit button is not always sent. See my in depth article about this here:

    The IE if (isset($_POST['submit'])) bug explained.
    I can't really think of anything to write here now...

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,694
    Thanks
    25
    Thanked 657 Times in 656 Posts
    @Blainyckz,
    These things are easy to do, but we need your code. to show you how to adapt it. Validating forms should be done with javascript and then again in the php code. The "thanks, your message has been received" again, is not hard to do. I see ajax for form submission and JS to bring the message to the forefront.

    You should do this in steps starting with the validation.
    Blainyckz likes this.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    New to the CF scene
    Join Date
    May 2014
    Location
    London, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the code I'm using any help would be great thank you

    PHP Code:
    <?php
    //--------------------------Set these paramaters--------------------------

    // Subject of email sent to you.
    $subject 'Alt-UK Application'

    // Your email address. This is where the form information will be sent. 
    $emailadd 'jobs@alt-uk.co.uk'

    // Where to redirect after form is processed. 
    $url 'http://alt-uk.co.uk/'

    // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
    $req '1'

    // --------------------------Do not edit below this line--------------------------
    $text "Results from form:\n\n"
    $space ' ';
    $line '
    '
    ;
    foreach (
    $_POST as $key => $value)
    {
    if (
    $req == '1')
    {
    if (
    $value == '')
    {echo 
    "$key is empty";die;}
    }
    $j strlen($key);
    if (
    $j >= 20)
    {
    $space .= ' ';}
    $value str_replace('\n'"$line"$value);
    $conc "{$key}:$space{$value}$line";
    $text .= $conc;
    $space ' ';
    }
    mail($emailadd$subject$text'From: '.$emailadd.'');
    echo 
    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    ?>

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,694
    Thanks
    25
    Thanked 657 Times in 656 Posts
    This line:
    // Where to redirect after form is processed.
    $url = 'http://alt-uk.co.uk/';

    Tells you where the form redirects to. Just change that to a HTML page that says "thanks your message has been received". that's all there is to it.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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