0

I finished a website and when I tried to move the website, the rewrite rules didn't work as planned. Now the website works but my contact form is the only thing that doesn't work. The error that I get is the unidentified index:save in contact.php on line 87. It has something to do with this line of code:

if (isset($_GET['save']) || $_GET['save'] == 'contact') {        
include('contact-form-submit.php');

Before the migration, the whole site worked perfectly.

This is the contact form:

<?php  
                    // check for a successful form post  
                    if (isset($_GET['s'])) echo "<div class=\"alert alert-success\">".$_GET['s']."</div>";  

                    // check for a form error  
                    elseif (isset($_GET['e'])) echo "<div class=\"alert alert-error\">".$_GET['e']."</div>";  
                    ?>                          
                    <form method="POST action="contact.php">  
                        <input class="input-xlarge" name="contact_name" type="text" placeholder="Naam" <?php if(isset($_GET['contact_name']) && !isset($_GET['s'])) print 'value="'.$_GET['contact_name']. '"'; ?>> <br/>
                        <input class="input-xlarge" name="contact_tel" type="text" placeholder="Telefoonnummer" <?php if(isset($_GET['contact_tel']) && !isset($_GET['s'])) print 'value="'.$_GET['contact_tel']. '"'; ?>><br/>
                        <input class="input-xlarge" name="contact_email" type="text" placeholder="E-mail" <?php if(isset($_GET['contact_email']) && !isset($_GET['s'])) print 'value="'.$_GET['contact_email']. '"'; ?>><br/>
                        <input class="input-xlarge" name="contact_onderwerp" type="text" placeholder="Onderwerp" <?php if(isset($_GET['contact_onderwerp']) && !isset($_GET['s'])) print 'value="'.$_GET['contact_onderwerp']. '"'; ?>><br/>
                        <textarea rows="6" name="contact_message" placeholder="Typ uw vraag" <?php if(isset($_GET['contact_message']) && !isset($_GET['s'])) print 'value="'.$_GET['contact_message']. '"'; ?>></textarea><br/> 
                        <input type="hidden" name="save" value="contact"> 
                        <button type="submit" class="btn">Verstuur</button>                   
                    </form>
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
user2314339
  • 395
  • 1
  • 6
  • 16

2 Answers2

2

Three problems:

1

 if (isset($_GET['save']) || $_GET['save'] == 'contact') {  

The isset part is there to avoid the PHP Notice by taking advantage of short-circuiting (so that $_GET['save'] == 'contact' is only evaluated if $_GET['save'] does in fact exist), but you're supposed to write &&, not ||.

This must have been masked by weak error reporting settings on your previous platform; it looks like you've migrated your site content but not your server settings... oops!

2

Another problem is that your form's action is "POST action=", because you forgot a " in your HTML:

<form method="POST action="contact.php">

You should turn syntax highlighting on in your text editor so that you can spot such silly typos yourself.

3

Finally, when you've fixed your form method to be POST, $_GET will still not be populated with your form values, because $_POST is used instead.

There is no way that this worked before, unless you have code elsewhere that automatically moves $_POST into $_GET to standardise between the two form methods (I do this sometimes). However, you have not shown us this.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • There's also the issue of the missing " after method="POST – Dave Apr 24 '13 at 09:41
  • Thank you so much for commenting my problem. Really appreciate it. It changed GET into POST and now i don't see the error. Only when i press send, i get the 404 page. He can't seem to work with the code in a way. Does that have to do something with the server settings? – user2314339 Apr 24 '13 at 10:27
  • EDIT: NEver mind i found out what the problem was action was "contact.php" but i changed it to 'contact' because of the rewrite. Thanks again for helpin me! – user2314339 Apr 24 '13 at 10:33
  • @user2314339: You've obviously done much more than simply move your website. In future, try to change _one thing at a time_ only. – Lightness Races in Orbit Apr 24 '13 at 10:34
0

This is because you are using form method as POST and trying to get it using _GET use $_POST['save']. So change your if condition to

if (isset($_POST['save']) && $_POST['save'] == 'contact') {  
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45