PHP not working correctly in WordPress - php

I have made a plain PHP widget to be displayed on a WordPress sidebar. I have successfully made the widget post the data I am hoping to have filled in on the consecutive page. However where it is supposed to be will not fill in, instead it fills in with "<?php echo $_GET[" then after the text box " />". I am hoping that the email first submitted will fill in on the form on the next page. The code that I have for the registration form is part of a greater widget and looks like the following:
<p class="form-email'.$errorVar.'">
<label for="email">'. __('E-mail', 'profilebuilder') .$errorMark.'</label>
<input class="text-input" name="email" type="text" id="email" value="<?php echo $_GET["email"]; ?>" />
</p><!-- .form-email -->';
Here is a link to the page: http://universityoutfitters.com/testphp/ — the widget is on the bottom left hand side panel.
Additional information:
The code for the widget is as follows:
<form action="http://universityoutfitters.com/sign-up/" method="post">
Please submit your email address
Email: <input type="text" name="email" />
<input type="submit" />
</form>

This line should be:
<label for="email"><?php echo __('E-mail', 'profilebuilder') $errorMark ;?></label>

As the comments told above, you have to wrap it correctly with PHP tags
<?php
echo '<p class="form-email'.$errorVar.'">
<label for="email">'. __('E-mail', 'profilebuilder') .$errorMark.'</label>
<input class="text-input" name="email" type="text" id="email" value="'.$_GET["email"].'" />
</p><!-- .form-email -->';
?>

Related

Ajax call on submit refreshing page

Problem
My page seems to be defaulting to my PHP code instead of being handled asynchronously via ajax. As of now, my page just reloads as a blank screen, the input array successfully got passed over to the PHP, which is comforting, but I seem to just be doing something wrong with the ajax.
What I've tried
After viewing this link and this link, I still cant seem to get this figured out.
Current Standing
Here is the HTML:
<form class="cmxform" id="commentForm" method="" action="">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<p>
<label for="spinner">How much do you love science? (optional)</label>
<input id="spinner" name="spinner">
</p>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required>
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required>
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url">
</p>
<p>
<label for="aoi">Area of Interest (optional)</label>
<input id="aoi" type="text" name="aoi">
</p>
<p>
<label for="currprobs">Current Problems (optional)</label>
<input id="currprobs" type="text" name="currprobs">
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p>
<input id="launch" type="submit" value="Submit">
</p>
</fieldset>
</form>
<div id="results"></div>
Here is the javascript:
$(document).ready(function(){
$("#commentForm").submit(function(event){
/*
var formData = {
'name' : $('input[name=name]').val(),
'email' : $('input[name=email]').val(),
};
*/
alert("SUCCESS?");
});
});
PHP code to return a div after the user has been validated:
<?php
$username = isset($_POST['name'])? trim($_POST['name']):'';
$email= isset($_POST['email'])? trim($_POST['email']):'';
echo '<div id=dynamicDiv>
<p>Hello, '.$username.'!</p>
<p>We look forward to contacting you at, '.$email.'</p>
</div>';
?>
Feedback
Any thoughts are appreciated, even intellectual conversation. Code snippets are idea, but I appreciate anything the community is able
Edit 1
I motified the javascript and php to reflect knowledgable input and best practice for PHP and AJAX calls, however the issue still remains.
Edit 2
My goal now is to just get an alert() statement working inside of my javascript, ajax will be the next step.
I think problem is here
$("#results").html = html_i;
You try change to
$("#results").html(html_i);
And in php you should check name and email
$username = isset($_POST['name'])? trim($_POST['name']):'';
$email= isset($_POST['email'])? trim($_POST['email']):'';
You should change input type="submit" to input type="button" and call Ajax on onclick function, Its resolve your problem because submit button submit form and Ajax call pending not reached to 400 state.

One submit button multiple actions PHP

I have a form below which creates a lead on my Insightly CRM:
<form abframeid="iframe.0.2052424988" abineguid="77AFC49A87B39B622E" action="https://xxxxxxx.insight.ly/WebToLead/Create" method="post" name="insightly_web_to_lead">
<input name="formId" type="hidden" value="Wby7PPWJNXwWA==">
<label for="insightly_firstName">Name*: </label> <input id="insightly_FirstName" name="FirstName" required="" style="width: 300px;" type="text"><br>
<label for="insightly_lastName">Surname*: </label><input id="insightly_LastName" name="LastName" required="" style="width: 300px;" type="text"><br>
<label for="email">Email*: </label><input id="insightly_Email" name="email" required="" style="width: 300px;" type="email"><br>
<label for="Description">Message*: </label><textarea id="insightly_Description" name="Description" required="" style="width: 600px; height: 150px;"></textarea>
<input id="insightly_ResponsibleUser" name="ResponsibleUser" type="hidden" value="1125264"><br>
<input id="insightly_LeadSource" name="LeadSource" type="hidden" value="1032448"><br><input type="submit" value="Submit"> </form><p> </p>
I would like the form to create the CRM Lead + a copy of the contents of be sent to my email address + open a thank you page, so I created the insightly_form.php below which I then used to replace the action above.
<?php
include('https://xxxxxxx.insight.ly/WebToLead/Create');
include('MAILTO:myname#mydomain.com');
?>
<?php
header("Location: http://www.mywebsite.com/thank-you");
?>
The PHP scripts run because it opens the thank you page fine, but no copy is sent to my email nor the lead is created. What am I missing?
Anybody can help, please?
'MAILTO:myname#mydomain.com' is a link which will open email apps when user clicked it.
Instead, you should include the php script which will send email.
<?php
include('https://xxxxxxx.insight.ly/WebToLead/Create');
include('send_me_an_email.php');//write a script send_me_an_email.php to send you the email
?>
<?php
header("Location: http://www.mywebsite.com/thank-you");
?>
Also please refer to this page: http://php.net/manual/en/function.mail.php
I think you can use/modify 2nd example as per your needs.

PHP echo works on Page A but not on Page B

My goal is to populate a hidden form field with the utm_source from url.
Basically this:
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
The problem is this form works perfectly on one page, but not on another.
Working: museumhack.com/test-a/?utm_source=hello (form field is hidden, but populates value)
Not working: museumhack.com/test-b/?utm_source=hello (at the bottom)
It seems like the pages may be processing the double quotes differently, but not clear how to fix. Wordpress required a plugin to process on page PHP -- I installed that and don't think it's the problem.
Here is the entire form that I copy/pasted between pages:
<form action="http://museumhack.createsend.com/t/d/s/ihhykl/" method="post" id="lead-capture">
<p>
<input id="fieldName" name="cm-name" type="text" placeholder="Your Name"/>
</p>
<p>
<input id="fieldEmail" name="cm-ihhykl-ihhykl" type="email" placeholder="you#email.com" required />
</p>
<p>
<input id="fieldjuuilj" name="cm-f-juuilj" type="text" placeholder="(212)555-5555" />
</p>
<p>
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
</p>
<p>
<button type="submit">Request Quick Quote</button>
</p>
Thanks,
Try this code , this might help you
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET['utm_source']='';?>">

Scroll down to contact form at bottom of page when form is submitted with errors

What I'm trying to accomplish is when a user tries to submit the form with errors and the error messages are added/page reloads I need the page to automatically scroll down to the bottom of the page to the contact form location.
I currently have the form within my footer.php and I'm including it in on each page like this: <?php include('includes/footer.php') ?>
here is my html for the form:
<form method="post" action="#">
<input name="name" placeholder="Name*" type="text" value="<?php echo htmlspecialchars($name);?>">
<span class="error"><?php echo $nameErr;?></span>
<input name="email" placeholder="Email*" type="email" value="<?php echo htmlspecialchars($email);?>">
<span class="error"><?php echo $emailErr;?></span>
<input name="phone" placeholder="Phone #" type="tel" />
<textarea name="message" placeholder="Message*"><?php echo $message;?></textarea>
<span class="error"><?php echo $messageErr;?></span>
<input id="submit" type="submit" name="submit" value="Send" />
</form>
EDIT -
Based on the answer below this is what fixed my problem...
<form method="post" action="#footer">
//everything here
</form>
While redirect to the page with error msg, add #id_of_form_or_div in your url.
Add id to your form or div which containing the form. If you add their id in url, then page will move to that particular section.
For example, You have id for footer as footer. Then you url will be
www.domain.com/index.php#footer
You can also print a javascript variable to know if there are errors, then with javascript scroll to the form.
something like:
var erros = "<?php echo $errors ?>";
<script>
if (errors) {
document.getElementById("form_id").scrollIntoView();
}
</script>

How to pass the data in the input type using php

Hi, I want to know how to pass the data into the input type field; I'm using only $_POST method and also I did not use the database first. Please help.
form.php
<form action="booking.php" method="post">
<p>
I want to be pick up at:
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="pickupplace" id="pickupplace" autocomplete="off" tabindex="1" style="width: 260px;"/>
</p>
<p>
drop off at
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="dropoff" id="dropoff" autocomplete="off" tabindex="2" style="width: 260px;" />
</p>
</form>
in the booking.php
<div>
<p>From</p>
<p>
<p>
<?php
if(isset($_POST['pickupplace']) == NULL){
echo "-";
}
else{
echo $_POST['pickupplace'];
}
?></p>
</div>
in the edit_ride.php
<div>
<p>From</p>
<p>
<input type="text" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>
</p>
</div>
i want to pass the data into the edit_ride.php in the input type please help here it is,
What you can do is, you can merge edit_ride.php and booking.php, so that directly you can display the values using
<input type="text" name="pickupplace" value="<?php echo $_POST['pickupplace']" placeholder="Enter Address, Airport, Landmark"/>
This may not be the only solution, as some time we need multiple pages, in that case you may consider sessions or cookies also.
Alternatively, you can pass the values from one page to another using querystring ($_GET) method also without submit the forms in internal pages.
why are you specifying the form action booking.php if you need to submit your data on edit ride.php
so first of all change the form action to edit_ride.php and then recieve the data in your textbox as following on the page edit_ride.php
<input type="text" value="<?php if(isset($_REQUEST['pickupplace'])) echo $_REQUEST['pickupplace']; ?>" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>

Categories