Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, 19 February 2017

PHP Form submit without java script and submit button

Submit a form without submit button and  javascript submit

We mostly prefer php form submit either using javascript or normal submit.

But we can submit a form without submit button and  javascript

have a look at the below code



<?php

if(isset($_POST['submit_x']) && isset($_POST['submit_x']))
{
      echo $_POST['first_name'];
      echo $_POST['last_name'];

      // Save logic

}
?>


<form method="post">
<lable>First Name</lable>
<input type="text" name="first_name" >

<lable>Last Name</lable>
<input type="text" name="last_name" >

<input type="image" name="submit"/>
</form>

Saturday, 10 January 2015

Php for each with comma separator except last


Sometimes we write a logic to show comma separated data. But the challenge is not to append comma to the last value.
We can do this by using next() function:
 
<?php
$arr = array('tvs','hero','honda','bajaj');
$copy = $arr;
foreach ($arr as $val) {
    echo $val;
    if (next($copy )) {
        echo ','; // Add comma for all elements instead of last
    }
}
?>