Email validation using PHP

I have a form for which i am trying to validate the email address. If the email address is incorrect i want a value of “Please type a valid email address.” to be returned into the “email” input box on the form. What am i doing wrong? No validation is taking place. I receive the form information at my email and once submitted the user is sent to the “Thank you” page, but no validation. I can put anything in the “email” input and the form will submit.

<form action="../php/contact.php" method="post">
  <p>First Name:</p>
   <input class="box_style" type="text" name="first_name" required maxlength="20" />

  <p>Last Name:</p>
   <input class="box_style" type="text" name="last_name" required maxlength="25" />

  <p>Email:</p>
   <input class="box_style" type="text" name="email" required maxlength="50" />

   <p>Contact Number (optional):</p>
   <input class="box_style" type="text" name="contact_number" maxlength="12" />

  <p>How did you find us?</p>
  <select class="box_style" name="how" required>
    <option value="choose">Select...</option>
    <option value="referal">Referal</option>
    <option value="website">Website</option>
    <option value="search">Search Engine</option>
    <option value="card">Business Card</option>
 </select> 

 <p>Enquiries:</p> 
  <textarea class="box_style" name="inquiries" cols="30" rows="10"></textarea>

  <input class="box_style" type="submit" name="submit" value="Submit"/>   
 </form>

and this is the php

<?php

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

// define variables and set to empty values
$fName = $lName = $email = $cNum = $how =  $enquiries = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
$fName = test_input($_POST["first_name"]);
$lName = test_input($_POST["last_name"]);
$cNum = test_input($_POST["contact_number"]);
$how = test_input($_POST["how"]);
$enquiries = test_input($_POST["enquiries"]);

$email = test_input($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    print  "<p>Please type a valid email address.</p>";

header("Location: www.mysite/thankyou.com");
}};

$email_from = 'my@email.com';
$email_subject = "New Inquiry";
$email_body = "You have received a new message from" ." ". "$fName" ." ".    "$lName" ."n".
"$inquiries"."n".
"Referal Type:" ." ". "$how" ."n".
"Contact Number:" ." ". "$cNum" ."n";

$to = "my@email.com";
$headers = "From: $email_from rn";
$headers .= "Reply-To: $email rn";
mail($to,$email_subject,$email_body,$headers);


?>

Thank You


Source: stackoverflow-php

form button deleting data by clicking it

My web page is a forum where users can post text and images, then have them displayed on the web page. There is a like and dislike button that is output with each post. Everything works fine except when I hit the like or dislike button the post deletes itself; however, the likes are saved in my database, so I can tell there’s nothing wrong with my queries, so is there something wrong with my form?

Here it is,

//not full file
            if (isset($_GET['postid'])) 
            {

                if (!connect::query('SELECT post_id FROM dry_likes WHERE post_id=:postid', array(':postid'=>$_GET['postid']))) 
                {
                       connect::query('UPDATE dry_posts SET likes=likes+1 WHERE id=:postid', array(':postid'=>$_GET['postid']));
                       connect::query('INSERT INTO dry_likes VALUES (null, :postid)', array(':postid'=>$_GET['postid']));
                } 



                if (!connect::query('SELECT post_id FROM dry_dislikes WHERE post_id=:postid', array(':postid'=>$_GET['postid']))) 
                {
                       connect::query('UPDATE dry_posts SET dislikes=dislikes+1 WHERE id=:postid', array(':postid'=>$_GET['postid']));
                       connect::query('INSERT INTO dry_dislikes VALUES (null, :postid)', array(':postid'=>$_GET['postid']));
                } 

            }


            $dbposts = connect::query('SELECT * FROM dry_posts ORDER BY id DESC');
            $posts = "";

            foreach($dbposts as $p){
                    if (!connect::query('SELECT post_id FROM dry_likes WHERE post_id=:postid', array(':postid'=>$p['id']))&&!connect::query('SELECT post_id FROM dry_dislikes WHERE post_id=:postid', array(':postid'=>$p['id']))) {
                            $posts .="<img src='".$p['postimg']."'>".htmlspecialchars($p['body'])."
                            <form action='try.php?postid=".$p['id']."' method='post'>
                                    <input type='submit' name='like' value='Like'>
                                    <span>".$p['likes']." likes</span>
                                    <input type='submit' name='dislike' value='Dislike'>
                                    <span>".$p['dislikes']." dislikes</span>
                            </form>
                            <hr /></br />
                            ";

                    } 

            }

Here’s the form

<form action='try.php' class = "forum" method="post" enctype="multipart/form-data">
<textarea name="postbody" rows="4" cols="60" class = "text">

</textarea>
         <br />Upload an image:
        <input type="file" name="postimg">
        <input type="submit" name="post" value="Post">
</form>


Source: stackoverflow-php

jQuery add form row how to process php

Allright, i’m creating a little system so customers can place online their order with us. We will receive by email the order and process it in our own system.
They will place a order on a page, with some basic information they need to fill in. After that they need to fill in their order.
Each order line has 3 fields. Partnumber, Quantity and Price. Price will be a readonly and wont be submitted. Only showing the price.

I want to create with jQuery a small input field and a plus icon. When you type in 10 and click on the plus icon, their will be 10 extra rows of 3 fields. This i didnt create yet, but now you know how i want to work.

The problem is how will i handle the form? The fields are required, but i would like when just a line is empty, it wont be submitted or ignored in PHP. So i only want to check the forms that has been filled in. How should i create the form names?

Here some PHP:

if(toxInput::exists()){
if(toxToken::check(toxInput::get('token'))){

    $toxValidate = new toxValidate();
    $toxValidation = $toxValidate->check('$_POST', array(
            'po'            => array('required' => TRUE),
            'date'      => array('required' => TRUE),
            'bo'            => array('required' => TRUE),
            'remarks'   => array('required' => TRUE)
    ));

    if($toxValidate->passed()){
        echo 'Run insert';
    }
}
}

Here a screenshot of the form how it looks: http://prntscr.com/eigfc2

Here the HTML of the form:

<p><h2>Items</h2></p>
                            <p class="order">
                            <label  style="margin-left:20px;">Partnumber:</label><br />
                            <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                            </p>
                            <p class="order" >
                            <label style="margin-left:20px">Qty</label><br>
                            <input type="text" id="qty" name="qty" style="margin-left:20px;" class="text small" placeholder="Qty" />
                            <p class="order">
                            <label style="margin-left:20px">Price</label><br>
                            <input type="text"  style="margin-left:20px;" class="text small" placeholder="Price" readonly /><br>
                          </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>
                        <p>
                        <input type="text"  style="margin-left:20px;" class="text medium" placeholder="SP partnumber" />
                        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" />
                        <input type="text"  style="margin-left:16px;" class="text small" placeholder="Price" readonly />
                      </p>

                        <input type="hidden" name="token" value="<?php echo toxToken::generate(); ?>">

I know about the margins, needs to be nice in a class but was for testing.


Source: stackoverflow-php

How can I submit form data from a foreach loop?

This is my form:

<form action="update.php" method="post">
    
<button type="submit"> Submit</button> </form>

I insert data via Ajax:

 $.ajax({
     url: "data.php",
     data: {
         id: id,
     },
     type: "POST",
     success: function(data) {
         $("#data").html(data);
     }
 })

data.php:

<?php
$pdo = $db->prepare("SELECT * FROM data WHERE id = ?");
$pdo->execute(array($id));
while ($row = $pdo->fetch(PDO::FETCH_ASSOC))
    {
   ?>
   <input name="id[]" type="text" value="<?php echo $row['id'];?>">
   <input name="name[]" type="text" value="<?php echo $row['name'];?>">
<?php
}

As an Output I have for example:

2  Jim
3  Alan
5  Bob

Now in my update.php I want to update my data in the mySQL database:

<?php
foreach($_POST['id'] as $key => $value) {
    $id = $_POST['id'][$key];
    $name = $_POST['name'][$key];
    $pdo = $db->prepare("UPDATE data SET name=?, WHERE id=?;");
    $pdo->execute(array(
        $name,
        $id
    ));
        echo $id." ".$name;
}

As a result I expect to get again:

2  Jim
3  Alan
5  Bob

But what happens, I get only:

2  Jim


Source: stackoverflow-php

What do you use in production for React.js forms?

What do you do with big complicated forms in production with React.js?
We have tried both free avalible alternatives:

react-redux-form,
redux-form

Both of them were waste of our week and were causing lagging on big forms while user types or do some actions , because they simply try to re-render everything in form on every update of store.
Even implementing custom shouldComponentUpdate update or using PureComponents did not help because they were calling 45% of time performUpdateIfNecessary


Source: stackoverflow-javascript