I have the following form in my HTML. The form is used to submit the data to a PHP file, which would then send notifications to android Phones. Now I would need an addition. I need to submit the same data to another PHP file, which would submit the data to another PHP page, which would send the notifications to Apple devices. I prefer to use two different PHPs for andorid and iOS. How can I place two buttons for the same form? The below is my HTML form.
<form action="notifdatabaseonlyios.php" method="post">
<label class="lb">Title</label>
<input type="text" name="title" class="form-control" />
<label class="lb">Description</label>
<textarea class="msg" name="desc"></textarea>
<br>
<input type="hidden" name="type" value='notification'>
<button class="btn btn-info pull-right">Submit</button>
</div>
</form>
one method:
Give 2 buttons in the form with different button names, If user clicks the first button go to notifdatabaseonlyios.php
if ($_POST['button1'])
{ }
else if($_POST['button2'])
{ }
?>
Related
I am using a simple HTML to post. It works well but sometimes randomly would not post. I have deduced that it when the user clicks on the font-awesome icon. When a user clicks on the button in an area outside of the icon, the form functions correctly.
I have tried using span but that doesn't made a difference.
<form method="post" target="votar">
<label>Subject</label>
<input id="subject_input" name="subject_input" type="text">
<label>Message Body</label>
<textarea id="body_input" name="body_input"></textarea>
<button id="submit_btn" name="submit_btn" type="submit"><i class='fa fa-paper-plane'></i></button>
</form>
If it helps, I'm also using this PHP to send the form.
// Get data from form
$body_input=isset($_POST['body_input'])?$_POST['body_input'].'body append':'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input'].'sub append':'';
// Loop sending a message for each recipient
foreach(array_column($user_ids, 'user_id') as $user_N) {
send_msg($user_N, $body_input, $subject_input);
}
try
var_dump($_POST);
and check, maybe an error here:
target="votar",
i don't see an isset post for your button
if(isset($_POST('submit_btn')){
$body_input=isset($_POST['body_input'])?$_POST['body_input'].'body append':'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input'].'sub append':'';
}
you can add your foreach in as well where it needs to be
Here's what I'm looking to accomplish. When a user creates a profile they fill out some information with a form. After they submit the form the information is displayed on their profile. One of the form fields is going to be a button that other users can click to do an action. To display the button this is the PHP I currently have:
add_action('kleo_bp_after_profile_name', 'my_profile_button');
function my_profile_button()
{
echo 'Talk';
}
I need to input the form information into the href="#" spot. Does anyone know a way around this?
Thanks.
It sounds like you want to simply submit a form that a user fills out. If that is the case, you can't use a link, but you need to use a button:
<form action="submitpage.php" method="post">
Name: <input type="text" />
<input type="submit" value="Some Text" />
</form>
or
<form action="submitpage.php" method="post">
Name: <input type="text" />
<button type="submit" class="success button radius show-for-small">Some Text</button>
</form>
Sure, if you have captured that information with a POST variable, named 'redirect' for example, you could use it to generate a button. The problem is that I don't understand very well what you mean with be put into href="#" spot, because buttons don't have that property, so I write you the code to use it on a redirection which is done at clicking the button:
<input type="button" value="submit" onclick="location.href='<?php echo $_POST["redirect"];?>';">
If you want to use information in a link, which actually have href property use this:
<a id="link" href="<?php echo $_POST['redirect'];?>">Text of the link</a>
I need little help i am making an upload page, so i have two different forms and two different action
form is ajax picture upload (profile picture of user) its working fine action is action='ajaximage.php'
form is simple user info details like Name,Bio, etc etc. its also working fine.. and its action is action="add.php"
Doubt/Problem
In my website input boxes are not arranged orderly because of the design.
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<b>Tittle</b>
<input type="text" name="name">
</form>
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
<input type="file" title="Choose Image" name="photoimg" id="photoimg">
</form>
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<b>Description</b>
<textarea name="description" rows="1" cols="1"></textarea>
<button input="submit">Save Changes</button>
</form>
Ajax image uploader is working but in case of add.php it is working only for Description.
I cannot change the design so how can it be solved ?? Please Help
You need one submit button for each form. A submit button will just submit the form it is in.
#bwoebi is right about the submits but I'd be very surprised if your arrangement would work anyway. By my reckoning you have 3 forms. Just using the same name again wouldn't work. A single form needs to be distinct - unless you want to do a whole lot of javascript processing on submit. Have another look at fixing your layout to keep forms together.
Just saw your comments above. Why have separate forms with separate actions anyway? Why not have one form with one action that simply does both the file upload and adds the details (presumably to a database)?
You could also simply have different submit buttons on your form and add an onclick attribute to each setting the action for the form to be different:
<input type="submit" name="sub1" value="Upload Image" onclick="document.myform.action='ajaximage.php';">
<input type="submit" name="sub2" value="Add User" onclick="document.myform.action='add.php';">
This means the form action will be changed depending on which submit button is used .
To upload images via ajax you do not need to submt a form, that is the whole point of doing it via ajax. You can upload the image, and then submit the form for the text inputs.
pseudocode:
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<input name="name"/>
<input name="profilePic" id="profilePic"/>
<input name="descrption"/>
</form>
You can then use javascript(I prefer jQuery) to upload your image via ajax, specifying #profilePic.
Also, you should look at: http://blueimp.github.io/jQuery-File-Upload/
For my php file, I need to grab the unique form name.
The php file is executed when a user clicks the submit button. However, there are multiple submit button each with the same id, but they all have unique names. I need the name when they click on the submit button.
you dont want elements in html with the same id - bad practice in general. Your page will likely load normally but an html validator will notice it as an error.
html validator: http://validator.w3.org/
without seeing your code, its difficult to give you a definitive answer. if you have miltuple forms you can use hidden inputs. e.g.
<input type="hidden" name="form_name" />
Otherwise you can use javascript to put data in the form when the button is clicked. example javascript using jquery
html:
<form id="formid" >
<button type="button" id="someid" onclick="submitForm('btn1')" />
<button type="button" id="someid" onclick="submitForm('btn2')" />
<input type="hidden" id="btnsubmitid" value="" />
</form>
js:
function submitForm(btnID){
$("#btnsubmitid").val(btnID);
$("#formid").submit();
}
1 way is to put a hidden input inside of your form.
<input type="hidden" name="formName" value="[name of form]" />
then in your php, you can get it using
$form-name = $_POST['formName'];
pretty sure there are other ways, but this came to mind first.
Recommend jQuery 1.6.4 ajax php form mail scripts?
I've been searching for script that fit jQuery 1.6.4 ajax php that I can use. Quite a lot that I've come across is part of script that is taking alot of time to put together. Is there anything that is clearly descriptive from start to finish. A form with check.php script too if that is possible.
I'm using a jQuery 1.6.4 form mail using ajax post with php script. A jQuery error message if a single input field is not filled.
To register a ID number and select module subject 1 or subject 2 with and submit. This will go to subjectData.mysql database
I've already designed a form mail using a jQuery 1.6.4.
<div class="field"><!-- Start Login-->
<form action="register.php" method="post" class="register">
<fieldset class="ui-widget ui-widget-content">
<label for="textinput1"><strong>Log in to register a module</strong></label>
<input id="textinput1" placeholder="people number" type="text" /></fieldset>
<fieldset data-role="controlgroup">
<input id="textinput2" placeholder="Password" type="password" /></fieldset>
<fieldset data-role="controlgroup" data-mini="true">
<input type="radio" name="radio-choice-1" id="radio-mini-1" value="modNo1" checked="checked" />
<label for="radio-mini-1">subject 1</label>
<input type="radio" name="radio-choice-1" id="radio-mini-2" value="modNo2" />
<label for="radio-mini-2">subject 2</label></fieldset>
<input type="submit" data-theme="a" name="submit" value="Register" />
<button data-theme="b" id="reset" type="reset">Reset</button>
</form>
</div>
<!-- END Login-->
</div>
I agree with prodigitalson, you need to know some php to write the code you need and build the response with php for the jquery ajax to receive it and do some javascript magic according to that response. But you have to code that custom bit.
The form will most likely send the POST data to check.php, where it will all be processed, and it will then build a json encoded respopnse to reply to the page with the form. You need then some javascript code on that page to:
Prevent default operation of the send button and bind to that click event the form submission with ajax.
Build the php code on check.php to do something with the POST data ($_POST array in PHP) and prepare a json encoded response (build an array and when done, echo the output of json_encodeing it).
build the javascript code to handle the ajax response from check.php
Some sample code on how to respond with php to a jquery ajax request here