How to Add Html in PHP - php

How I can echo the whole code below.. The problem is another echo inside of the button..
Thanks!
<button type="submit" id="addres" name="addres" <?php echo $addres_disabled;?> class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>

Try this:
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>';

This is way too small question. A bit google search would have helped you.
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>';

Something like that:
<?php
$addres_disabled = 'disabled';
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>';
?>
You can use it outside the <?php?> as you are already using, something like:
<?php
/*** Your php code ***/
$addres_disabled = 'disabled';
/*** Your php code ***/
?>
<button type="submit" id="addres" name="addres" <?=$addres_disabled?> class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>';
<?php
/*** Your rest php code ***/
?>
Close PHP tag, before starting your HTML, and after HTML, you can continue the PHP tags, depends on your rest code.

i think you can juste do :
<?php echo '<button type="submit" id="addres" name="addres" '. $addres_disabled .' class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>' ?>

Related

woocommorce disable redirect to cart page after submit

<div class="submit-group">
<button class="btn btn-green btn-large btn-full upper btn-book-ajax" type="submit" name="submit">
Book Now
<i class="fa fa-spinner fa-spin hide"></i>
</button>
<input style="display:none;" type="submit" class="btn btn-default btn-send-message" data-id="9278" name="st_send_message" value="Send message">
</div>
the button class="btn btn-green btn-large btn-full upper btn-book-ajax" has the same function have to " add to cart " button in woo commerce
I am looking to disable add to cart redirection after submitting

How to get values from a button

I have a form which goes through three steps. In step 2, I am asking the user to select a speciality by clicking the corresponding button. If they click a button, they should move to the 3rd and final step.
Here is the button code:
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="hair_stylist" >HAIR STYLIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="cosmetologist" >COSMETOLOGIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="makeup_artist" >MAKEUP ARTIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="barber" >BARBER</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="esthetician" >ESTHETICIAN</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="nail_technitian" >NAIL TECHNITIAN</button>
I don't think name will work here. Is there anything that can be done with data-*? How can I send and grab this value in PHP when the form is submitted?
Having a name is fine and necessary.
There are two problems.
You need actually have a value in order to send a value
You need the button to be a submit button in order to submit the form
Such:
<button
class="btn btn-primary nextBtn btn-proffessional"
type="submit"
name="profession"
value="hair_stylist">
Hair Stylist
</button>
Then in PHP you can simply:
do_something_with($_POST["profession"]);
You can also use jquery Post function for this.
First little bit change your html code. Put your values inside id of your buttons
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="hair_stylist" id="HAIR STYLIST">HAIR STYLIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="cosmetologist" id="COSMETOLOGIST">COSMETOLOGIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="makeup_artist" id="MAKEUP ARTIST">MAKEUP ARTIST</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="barber" id="BARBER" >BARBER</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="esthetician" id="ESTHETICIAN" >ESTHETICIAN</button>
<button class="btn btn-primary nextBtn btn-proffessional "
type="button" name="nail_technitian" id="NAIL TECHNITIAN" >NAIL TECHNITIAN</button>
Then Some jquery code here:
$(document).ready(function () {
$('.nextBtn').on('click', function () {
$.post("NewPage.php",
{value: this.id
});
});
});
After clicking button. That particular button will be accessed by its class then it sends data to NewPage.php (You have to make new php page) where you can access value by POST array.
NewPage.php
If(isset($_POST['value']))
{
//Do your process here
}
Use the value parm.
Example:
<button class="btn btn-primary nextBtn btn-proffessional " type="button" name="hair_stylist" value="HAIR STYLIST">HAIR STYLIST</button>

PHP: if-else statement and mysql_num_rows not working

I'm working on a web page where a user will be allowed to add or edit a feedback for a place. If the person already gave the place a feedback, he/she will be shown an Edit Review button otherwise, the user will be shown an Add Review button.
In my feedback table in my database, I have a places_id and users_id column. Here's my query in PHP (Assuming that $id and $places_id have values):
<?php
$query5 = mysql_query("SELECT * FROM feedback WHERE user_id = '$id' AND places_id = '$places_id'");
$row5 = mysql_fetch_array($query5);
if($row5['user_id'] != $id){
?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Review</button>
<?php }else{ ?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Edit Review</button>
<?php } ?>
I was thinking that if the query did not return a result where the given user_id is not equal to the user_id in the result, it would let me do my if-else condition. However if there is a feedback for a current place, it displays the button found in the else statement.
What do you think is the problem and why is the if condition not working?
I also tried if(mysql_num_rows($query5)==0) but it's also not working.
I would always do:
<?php
$query5 = mysql_query("SELECT * FROM feedback WHERE user_id = '$id' AND places_id = '$places_id'");
if ($row5 = mysql_fetch_array($query5)) {
?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Edit Review</button>
<?php }else{ ?>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button>
<button class="btn btn-primary" type="submit" name="submit">Review</button>
<?php } ?>

How to add (or subtract) a value by pressing the submit button PHP

I have the following code=>
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
These buttons submit the form to the same page. At the top of the page I have variable $t which is initialized at value '0' and is followed by the codes=>
$t=0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
Now as I press forward I want to increase $t and when I press back I want to decrease it. But because of the declaration at the top ($t=0;) it goes as far as '1' with 'forward' and as back as '0' with 'back' buttons. Can anyone think of a way of getting over this problem.
Thank you...
Add a hidden input, and store $t there. This gets posted upon submit:
<?php
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
?>
<input name="t" type="hidden" value="<?=$t ?>">
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="submit">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="submit">FORWARD</button>
You could use url parameter. Get instead of post. so that it stores the current value of variable $t i.e.
if (isset($_GET['t']))
{
$t = $_GET['t'];
}
else
{
$t = 0;
}
Something like that could be of some help
If you want to know what button makes the submit you need to change the buttons
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
to
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="s_button" type="submit" value="geri">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="s_button" type="submit" value="ileri">FORWARD</button>
in your controller
$button_s = $this->input->post('s_button');
if( isset($button_s)){
switch($button_s){
case 'geri':
//do somthing
break;
case 'ileri':
//do somthing
break;
}
}

hidden field how to remove last part of url?

I want to remove GET parameters from urls:
http://localhost/fadt/admin/edit_country.php?id=7
I want my URLs to become:
http://localhost/fadt/admin/edit_country
here is how links are currently generated:
<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
Instead of a button use an HTML form with the POST method.
Something like:
<form action="edit_country.php" method="post">
<input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
<input type="submit" class="btn btn-primary btn-xs fa fa-pencil" title="Edit"/>
</form>
in place of
<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
Then on edit_country.php use $_POST instead of $_GET.
This id can be manipulated just as easily as your button value so make sure you are authenticating executing user has permissions to perform action.
Update, using button:
<form method="post">
<input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
<button type="submit" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
</form>
Not clear the question but i think u need this
<?php
$a = explode('?','http://localhost/fadt/admin/edit_country.php?id=7');
echo rtrim($a[0], '.php')
?>

Categories